what procedure am I in ? Access 2007

  • Thread starter Thread starter nigelf
  • Start date Start date
N

nigelf

Is there any way of knowing what procedure (e.g. Function, sub) I am in at
runtime? I am looking to create a reasonable error handler and have it use
the current procedure...
 
nigelf said:
Is there any way of knowing what procedure (e.g. Function, sub) I am in at
runtime? I am looking to create a reasonable error handler and have it use
the current procedure...

Unfortunately not. Since you must insert the error hander code anway, many
of us use the free MZtools that will insert the error handling code + the
procedure/function name for you.

However, for any control/event on your form, you can get the function name
by grabbing the name of the control with the current focus, since the
procedure name is based on that....

some string = Screen.ActiveContorl.name

So, if you are in an after update event, then

Some string + "_AfterUpdate" is the current procedure name...
 
But MZTools does it!!

Albert D. Kallal said:
Unfortunately not. Since you must insert the error hander code anway, many
of us use the free MZtools that will insert the error handling code + the
procedure/function name for you.

However, for any control/event on your form, you can get the function name
by grabbing the name of the control with the current focus, since the
procedure name is based on that....

some string = Screen.ActiveContorl.name

So, if you are in an after update event, then

Some string + "_AfterUpdate" is the current procedure name...
 
nigelf said:
But MZTools does it!!

Yes it does. But it's actually looking at the name of the module and
procedure via the VBA text editor. It's not looking at that from
within the executing code.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
Tony Toews said:
Yes it does. But it's actually looking at the name of the module and
procedure via the VBA text editor. It's not looking at that from
within the executing code.

And, Nigel, you can do it the same way that MZTools does. In design view of
the VBA code, scroll upwards until you see the Procedure statement (Function
or Sub), highlight the name, and copy it and paste it into a statement
within that procedure that you will execute at runtime to display the name.
That's a little different than I understood the question you asked, but
because Access does not maintain the information you desire in a form that
is accessible at runtime, that is the only way I know to handle it.

Larry Linson
Microsoft Office Access MVP
 
Back
Top