Store current sub/function & module name in Variable

ozinm

Human Coffee Siphon
Local time
Today, 20:57
Joined
Jul 10, 2003
Messages
121
Hi all,
Does anyone know if there is a way to programmatically (is that a real word:confused:) access the name of the current sub?

Something like this:

Code:
Sub ProcA
    msgbox "Sub: " & me.SubName & "Module: " & me.ModuleName
end sub

Sub ProcB
    msgbox "Sub: " & me.SubName & "Module: " & me.ModuleName
end sub

The reason I want it is I've got some standard error checking on each of my procedures and I want them to report back more detail. I just don't want to go through each one manually setting the name of the sub to report back. If there's a way to get the name of the sub pragmatically I could just do a quick find and replace on the entire project.

As ever, thanks in advance for any and all help given.

TTFN
 
No I don't think there is a way to do that. I think you would have to use a global variable and have a line in each of your subs that sets the value for that variable.
 
No I don't think there is a way to do that. I think you would have to use a global variable and have a line in each of your subs that sets the value for that variable.

yup. thats what I'm afraid of. I don't really fancy doing that. There's A LOT of code there.

I was kind of hoping some nice chap out there had some nifty bit of code laying around that would query the procedure stack.

Oh well :(
 
access cookbook (chapter 7.2) gives a generic mechanism for maintaining a stack of procedure names (ie program flow). basically pushstack and popstack to add and remove procedure names from the stack. Recommends it for use in error handlers, as vba doesnt provide a solution (i suppose procedure names just become tokens in compiled code - the compiler wont need to know the procideure name)

just needs pushstack("myname") and popstack("myname") adding at relevant points of your code - depends how much of it you need to trace i suppose, as to how long it would take

really useful book generally
 

Users who are viewing this thread

Back
Top Bottom