Determining name of calling procedure

J

Jeff Hunt

I am trying to write a function that will produce a detailed message box
whenever an error occurs. Right now, my error handlers have all been set to
call the following function:

Public Sub generalErrorMsg()
MsgBox Err.Description & " (Error #" & Err.Number & ")" & vbCrLf & vbCrLf & _
"Please file a ticket and include this error number and description.", ,
"Error"
End Sub

Because these will be called from different procedures and different forms,
possibly even from different functions, I would like to determine what is the
name of the sub or function that called generalErrorMsg(). I know I could
change the function to accept a string and just pass the name of the calling
sub to the function when the function is called, but I would like to not have
to include that in every error handler. Anyone know of a way to do this?
 
M

Marshall Barton

Jeff said:
I am trying to write a function that will produce a detailed message box
whenever an error occurs. Right now, my error handlers have all been set to
call the following function:

Public Sub generalErrorMsg()
MsgBox Err.Description & " (Error #" & Err.Number & ")" & vbCrLf & vbCrLf & _
"Please file a ticket and include this error number and description.", ,
"Error"
End Sub

Because these will be called from different procedures and different forms,
possibly even from different functions, I would like to determine what is the
name of the sub or function that called generalErrorMsg(). I know I could
change the function to accept a string and just pass the name of the calling
sub to the function when the function is called, but I would like to not have
to include that in every error handler.


Years and years of trying to find a way and innumerable
feature requests to MS has yet to come up with an answer
beyond passing the name in an argument.
 
G

George Nicholson

Afaik, not possible. Wish it were.

You can however, pass the name of the calling procedure to generalErrorMsg
as an argument. That means you'd have to manually supply the argument
(procedure name) whenever you call it. That's what I do (but my generic
error sub also writes the procedure name, error number, error description,
Username & Date/Time to an "Event Log" table, because I don't like relying
on users to accurately inform me of problems. I'm funny that way :)

FYI: I also include an optional PromptUser argument because I use the
routine to create a log entry when certain things happen (login, logout,
certain functionality used) that don't require prompting the user.

HTH,
 
D

Daniel

Jeff,

This is when I would suggest you install a free add-in

http://www.mztools.com/

you can set up your error message the way you like and it will put in info
such as procedure name... etc. Save you the hassel of copy/paste....

Daniel
 

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