473,406 Members | 2,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Currently running function?

218 Expert 100+
Hi,

Here's a weird one!

Is there a known way to determine the name of the currently running Sub or Function in VBA code?

I'm trying to build a generic error-trapping funtion, to avoid writing hundreds of
Expand|Select|Wrap|Line Numbers
  1. ON ERROR GOTO..
blocks, with different parameter values.

I've been looking at ways to use the Windows API with AddressOf, etc, but I can't see how I can get this to work...

Any hints and suggestions welcomed

TIA

Steve
Dec 8 '06 #1
11 2711
NeoPa
32,556 Expert Mod 16PB
As the On Error statement can only branch within the current procedure surely you can just say
Expand|Select|Wrap|Line Numbers
  1. On Error GoTo ErrorCode
  2. ...
  3. ErrorCode:
in each one?
To answer your question though, i don't believe you can access that info from within the code.
Dec 8 '06 #2
cyberdwarf
218 Expert 100+
As the On Error statement can only branch within the current procedure surely you can just say
Expand|Select|Wrap|Line Numbers
  1. On Error GoTo ErrorCode
  2. ...
  3. ErrorCode:
in each one?
Yeah but... This app I've inherited has some 3500 Subs/Functions !!!
I was trying to avoid that much cutting & pasting (as well as the RSI)

Mebbe I just gotta move away from Access to get some decent exception handling?

I was thinking there may be some hidden calls in the VBA/Access dll's which use this info.

Ah well...

Thanks anyway, NeoPa

Steve
Dec 8 '06 #3
NeoPa
32,556 Expert Mod 16PB
Me.Module.Name will give you the name of the current module at least.
Dec 8 '06 #4
NeoPa
32,556 Expert Mod 16PB
As error handling is handled hierarchically, you can just put it in the higher level functions.
Alternatively, use a bit of code to process through your code in a text file, adding it to all procedures.
I use a text editor that could probably handle that.
Dec 8 '06 #5
ADezii
8,834 Expert 8TB
Hi,

Here's a weird one!

Is there a known way to determine the name of the currently running Sub or Function in VBA code?

I'm trying to build a generic error-trapping funtion, to avoid writing hundreds of
Expand|Select|Wrap|Line Numbers
  1. ON ERROR GOTO..
blocks, with different parameter values.

I've been looking at ways to use the Windows API with AddressOf, etc, but I can't see how I can get this to work...

Any hints and suggestions welcomed

TIA

Steve
'As previously suggested by NeoPa, place the Exception Handler high up in
'the proverbial Call Stack. As for the name of the currently running Sub or
'Function Procedure, a custom Property can be created appropriately named ProcedureName. It can be Set (Property Let) at the beginning of every Procedure and retrieved (Property Get) at will. Hope this helps...
Dec 8 '06 #6
NeoPa
32,556 Expert Mod 16PB
It's just clicked why you want this (no-one ever explains what they really want).
You already know about placing the routine at the top of the call-stack and want a way of setting the error message so that it indicates where the error occurred. Is that right?
Dec 8 '06 #7
cyberdwarf
218 Expert 100+
It's just clicked why you want this (no-one ever explains what they really want).
You already know about placing the routine at the top of the call-stack and want a way of setting the error message so that it indicates where the error occurred. Is that right?
Yup, right again, NeoPa

Sorry, I clearly didn't get that across in my post. My communication skills tend to disintegrate after 36 hours straight coding!
Dec 8 '06 #8
cyberdwarf
218 Expert 100+
'As previously suggested by NeoPa, place the Exception Handler high up in
'the proverbial Call Stack. As for the name of the currently running Sub or
'Function Procedure, a custom Property can be created appropriately named ProcedureName. It can be Set (Property Let) at the beginning of every Procedure and retrieved (Property Get) at will. Hope this helps...
Hi ADezii

Thx for your reply

My understanding of custom properties is that they can be applied within class modules. Unfortunately, the offending app is totally procedural (no class modules, no OO!) - hence my difficulties.

I'm not sure whether placing the Exception Handler high up in the Call Stack will work in these circumstances??

TIA

Steve
Dec 8 '06 #9
NeoPa
32,556 Expert Mod 16PB
You could get basic, module level, info as posted earlier, with Me.Module.Name but I know of nowhere that more detailed info is stored or referenced - sorry.
If you want to have a look see at other available properties then select View Watch Window from the view window and add a Watch called Me. You can then check through available items when the code is stopped within that module.
Dec 8 '06 #10
cyberdwarf
218 Expert 100+
You could get basic, module level, info as posted earlier, with Me.Module.Name but I know of nowhere that more detailed info is stored or referenced - sorry.
If you want to have a look see at other available properties then select View Watch Window from the view window and add a Watch called Me. You can then check through available items when the code is stopped within that module.
Hi NeoPa,
You still around??

Thx for the heads up on this stuff - Me.Module.Name does provide a start, but short of taking a sledgehammer approach, I can't see another way to crack this problem!!

Oh for a version of Try...Catch...Finally ;-)

Thx

Steve
Dec 8 '06 #11
NeoPa
32,556 Expert Mod 16PB
Hi NeoPa,
You still around??

Thx for the heads up on this stuff - Me.Module.Name does provide a start, but short of taking a sledgehammer approach, I can't see another way to crack this problem!!

Oh for a version of Try...Catch...Finally ;-)

Thx

Steve
Steve,

Yeah, I'm still up.
Just thought, if you need the sledgehammer then post #5 may at least be a step in the right direction.

Cheers -Adrian.
Dec 8 '06 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Brian | last post by:
On a Slackware 9.1 box, I'm trying to detect if mpg123 is currently running/playing a song so that when the song is done, it'll play the next in the list. The problem is that popen'ing ps doesn't...
3
by: CMan | last post by:
Hi, We are currently trying to install .Net Framework v.1.1 on a server which already has v1.0. We are receiving the following error. Error 1704.An installation for Microsoft .NET Framework...
11
by: MLH | last post by:
Suppose I'm in an open database (northwind.mdb). Is there a shorter form of doing the following after I've dim'd dbsNorthwind as database... Set dbsNorthwind = OpenDatabase("Northwind.mdb") ...
2
by: Yeounkun, Oh | last post by:
Hello, I want to know the name of function() in program. In "gcc", I know that __FUNCTION__ macro is used for getting that. but in "cc", __FUNCTION__ macro does not exist. I can't find function...
1
by: Vagabond Software | last post by:
I'm writing an application where then end-user will want to view and print (not edit) TIFF and JPEG images. For now, I simply use the System.Diagnostics.Process.Start method to open the desired...
2
by: SStory | last post by:
I have a service which has no U/I, that I use to ensure a certain tray application is running. I would like for the service which runs under "Local System", to create the process as a normal app...
4
by: bruno.fischel | last post by:
Hi, I was wondering if there was a way to know the absolute path of the library "currently running". For example, in my function foo, how can I get the path of the library containing the...
15
by: Mephisto187 | last post by:
How can I find the currently visible desktop? By calling EnumWindowStations and EnumDesktops I get a list of all available desktops. But is there a way to figure out which one of them is currently...
5
by: mivey4 | last post by:
Hi, First off, I am aware that this is a very heavily documented error and I have done my homework for throughly researching probable causes before deciding to post my problem here. At this point,...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.