How to Identify the Calling Function?

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
 
A

Allen Browne

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.
 
D

david epsom dot com dot au

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)
 

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