Currently Executing Procedure Name

G

Guest

Hello all,

I was wondering if there was any way to reference the name of the currently
executing procedure. Basically, I have error handler code in each procedure
in my database that looks something like:

Form_Load_Exit:
Exit Sub

Form_Load_Error:
Select Case Err
Case Else
MsgBox Err.Number & " - " & Err.Description
DoCmd.Quit
Resume Form_Load_Exit
End Select


What I would like to do is title the MsgBox with the name of the procedure
the error handler is in (ie, Form_Load in the code above) I know I could
hardcode it, but I would really like to be able to just drop in a command
that would do that automatically (I have a LOT of procedures to update, plus
it would be nice for consistency's sake between procedures). Any thoughts?
Thanks,

Matt
 
G

Guest

Set these two variables:

Dim frmCrnt As Form
Dim ctrlCrnt As Control
'Display error information
Set frmCrnt = Screen.ActiveForm
Set ctrlCrnt = Screen.ActiveControl
MsgBox "Control: " & frmCrnt.Name & "." & ctrlCrnt.Name & "; Error
number " & DataErrCode & ": " & DataErrDescription, vbCritical, "Control
Error"

This shows the current control & form name, along with the error # &
description. While it does not tell you the procedure, it does give you the
current control. Be aware that you may need to trap form-related errors
(Form_Error event) separately, since the syntax and variables are a little
different.

I created a function that sits in a module and is globally available. Then,
I pass the error number and name info to the function and have to put the
above code only in that module. The individual procedures just need to
reference the function.
 
D

Douglas J. Steele

Assuming you're using Access 2000 or newer, take a look at MZTools
http://www.mztools.com/

Among the many, many things this amazing free add-in does is allow you to
automatically add error handling that includes the procedure name. (It hard
cods the name automatically for you)
 

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