How can I tell what the calling event is?

bhavdahl

Registered User.
Local time
Yesterday, 18:22
Joined
Feb 4, 2008
Messages
17
Hope this isn't a stupid question. But is there a feature of some kind in VBA that will tell me what event called my subroutine? ...other than setting some kind of flag in the calling procedure. Like is there anything that will tell you what the currently executing event is as your sub routine starts? ...something like that.
 
There's a call stack, so the sequence in which currently executing subroutines have been called is available. Set a breakpoint in your code, and hit Ctrl + L, or Menu->view->Call Stack, or put a button on your toolbar.

Is that what you are looking for?
 
Thanks! But I was looking for a way to pass the name of a calling procedure to a subroutine, to do different things depending on which event called it for example.

A better way than setting some kind of flag that is. If there was one.
 
If your sub does different things depending on what event called it, rewrite it!! Do a search on coupling and cohesion to understand proper coding techniques.

To summarize, if you need to do a, b, and c when called from x and a, c, and d when called from y then you should break up the code so that you can call a and c separately so they are not coupled unnecessarily with b and d.
 
Bhavdahl.

What precisely is it that you are trying to do?

At runtime you can not determine the name of the calling procedure, not even the active procedure. You can pay for it but, as far as I know, not get it for free.

Even passing the name of the calling procedure would not be sufficient. Even if the procedure was behind a Form, passing the name of the Form and the procedure name would not be sufficient. A Form name + Procedure name can not be guaranteed to be unique.

So I think we need more information.

Chris.
 
Detail is probably gonna be difficult.

They are coupled necessarily in this case and its not all that messy.

Everything is behind one form so all event subroutines, etc are unique. Passing the name works. I was just thinking it might be useful in general to be able to tell that. If its not free then yeah, it isn't worth it.

Thanks.
 
So yeah, it is stupid to do that. I ended up doing something different after rethinking it. Thanks a lot for all the comments! That helped a lot.
 
out of interest, why do you need to know the calling proc? if it is just to determine which path to follow in the sub, just pass some suitable option indicator as you originally suggested
 
I figured knowing the last proc that executed might be cleaner sometimes, easier to keep track of, than setting and resetting some kind of switch.
 

Users who are viewing this thread

Back
Top Bottom