Getting Function or Procedure Name

  • Thread starter Thread starter Chaplain Pruiett
  • Start date Start date
C

Chaplain Pruiett

Presently when one of my functions or procedures gets an
error I use:

MsgBox Err.DESCRIPTION

Is there any object that contains the name of the
procedure or function in which the error occurs?
Something like,

Err.LOCATION

Or something like this? Thanks for the help.
 
Chaplain said:
Presently when one of my functions or procedures gets an
error I use:

MsgBox Err.DESCRIPTION

Is there any object that contains the name of the
procedure or function in which the error occurs?
Something like,

Err.LOCATION

Or something like this? Thanks for the help.

No, unfortunately there is no way to do that. This
capability has been requested since all the way back to A2.
It appears that it is an extremely complex issue that just
doesn't warrent the amount of work it would take to add it.
 
Thanks. I guess that's why the error handlers produced
automatically when you create a button control have only
err.description.
 
Chaplain said:
Thanks. I guess that's why the error handlers produced
automatically when you create a button control have only
err.description.

I consider that automatically generated code to be a minimal
outline, not a recommended way to do anything.

Personally, I thing the error number is at least as useful
as the description, so myminimal MsgBox is:

MsgBox Err.Number & " - " & Err.Description
--
Marsh
MVP [MS Access]

 
I noticed that when Access generates a function or
subroutine it puts the following in the routine:

On Error GoTo Err_CNPR

Exit_CNPR:
Exit Function

Err_CNPR:
MsgBox Err.DESCRIPTION
Resume Exit_CNPR

What does this really buy me? It seems that when an error
occurs the same thing happens (I get an unhelpful MsgBox)
whether I have this "error handler" or not. Thanks.
 
Chaplain said:
I noticed that when Access generates a function or
subroutine it puts the following in the routine:

On Error GoTo Err_CNPR

Exit_CNPR:
Exit Function

Err_CNPR:
MsgBox Err.DESCRIPTION
Resume Exit_CNPR

What does this really buy me? It seems that when an error
occurs the same thing happens (I get an unhelpful MsgBox)
whether I have this "error handler" or not.

If you remove the error handler code in a lower level
procedure, an error will then percolate up the the call
stack until it finds an error handler. You only get the
default error message box if there are no error handlers in
any of the procedures. The big problem is that the
procedure where you really do want to do something with an
error may be complicated by having to deal with errors in
any of the procedures that it calls. Besides, good
programming practices keep all code as local as possible.

The killer argument in favor of using error handlers in just
about every procedure id that unhandled errors reset all
global variables in all standard modules.
 
Back
Top