How to Identify the Calling Function?

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

I'm trying to implement a global error processing system
for my MS Access 2002 application. It would be much more
convenient for me if there was some way to identify the
name of the function that called the currently executing
function.

Example:

public sub main()
my_error_obj.assertCondition <condition check>
end 'main

Class my_error_obj
public sub assertCondition arg1
if <arg1 fails> then
err.raise number:=myErrNumber, _
source:=<calling procedure name> 'in
this case, it should be "main"

end if
end sub

Currently, I'm passing the calling sub name as an
argument, but I'm not satisfied with this solution. There
must be a way to identify the function that called the
current function (Call Stack does it) but I'll be damned
if I can figure out how to do it. Any ideas?

Thanks,
Dave
 
Hi Dave. VBA does not expose this.

As you say, it could do, but it never has.

What we do is use mztools (download from www.mztools.com ), which lets you
drop in the error handling configured how you want (including the procedure
name) with just a mouse click.
 
In your case, since you are raising an exception which will
be thrown back to the calling function, all you need is the
name of the current function. The calling function can
add it's name to the error object when it catches the exception.

BTW, the IDE can display the call stack when you pause/break,
so the information is sort of available from the VBA subsystem.
(It has been attempted, and it is not worth the effort.)

But when you make an MDE the symbols are discarded, so unless
you code the strings into your error handler, there is no way
at all to retrieve them in that situation.

(david)
 
Back
Top