Can I get form name / routine name from Access?

D

Dennis

Hi,

I’m using Access 2003.

I have the following line that I include in my ON ERROR routine:

Call BaseUtil.Dsp_Err_Msg(Err.Number, Err.Description,
"cbPrintReport_Click")

As you see, I currently hard code the name of my routine in my error message
so I can display it in the error message.

I have two questions.

1. Is there a way I can get the name of the current routine from Access so
I do not have to hard code it in each line?

2. Is there a way I can get the current form / report name from Access so I
do not have to hard code it in each line?

Ideally I would like to have the following lines of code in my ON ERROR
routines:

strFormInfo = FunctionToGetFormName & “ – “ & FunctionToGetRoutineName
Call BaseUtil.Dsp_Err_Msg(Err.Number, Err.Description, strFormInfo)

This way when I display the error message, I will automatically know which
routine generated the error message. The form name is really helpful when
I’m in a sub-form.

If I can not do the above, I will setup a standard variable for the form
name & routine name and then just set the variable to the appropriate value.

Thank you for your assistance.

Dennis
 
A

Allen Browne

Access (VBA) doesn't expose the name of the currently executing procedure
for you.

If the code is associated with a form (i.e. it's not in a stand-alone
module) the name of the current form is Me.Name. You could pass this as an
argument to your Dsp_Err_Msg() procedure.

Don't use Module.Name. That fails if you convert your database to an MDE.

There are some commercial add-ons that read the module/routine name, e.g.:
http://www.everythingaccess.com/simplyvba-global-error-handler.htm

What I do is to use the same constant in the General Declarations section
(top) of every module, but with its actual name, e.g.:
Private const conMod = "Form_frmClient"
and then use conMod in all code. Even if you copy'n'paste code between
modules, it stays right.

Then I use MzTools to drop the procedure name (and the whole error handler)
into your code:
http://www.mztools.com/v3/mztools3.aspx
 
D

Dennis

Allen,

One other question.


Can I add a "optional" fourth parameter to my Dsp_Err_Msg?

I would like to add Form Name as the fourth parameter of Dsp_Err_Msg.
However, I don't want to have to stop and change all of my code right now in
order to implement this change. I would rather make the changes over a
period of time.

I know I can create a second Dsp Err Msg routine with a different name and a
fouth parameter, but I would like to know how to declare optional parameters.
 
D

Dirk Goldgar

Dennis said:
Hi,

I’m using Access 2003.

I have the following line that I include in my ON ERROR routine:

Call BaseUtil.Dsp_Err_Msg(Err.Number, Err.Description,
"cbPrintReport_Click")

As you see, I currently hard code the name of my routine in my error
message
so I can display it in the error message.

I have two questions.

1. Is there a way I can get the name of the current routine from Access
so
I do not have to hard code it in each line?

2. Is there a way I can get the current form / report name from Access so
I
do not have to hard code it in each line?

In my standard error-logger, I use CodeContextObject.Name to get the name of
the object for which the code is executing. See the help-file entry (in the
VB Editor environment) for CodeContextObject. In Access 2003, at least, it
gives an example of this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top