Pass name of current sub and form variables to function

ML!

Registered User.
Local time
Today, 12:02
Joined
May 13, 2010
Messages
83
I know this will be a simple answer but I can't find it.

When an error is thrown, I want to capture the name of the current sub and the form object to a function that adds the error details to a table.

I'm going to pass the caption property of the form but how the heck do I get the name of the calling procedure?
 
I'm afraid not. It's really not as simple as you'd think.
There is no default (native VBA) means of acquiring the executing procedure name.
You can, of course, create a constant or variable - assign the value as standard and pass that.
Tools such as MzTools make including error handling and inserting the name as hard coded that little easier.
But ultimately, if you want this performed generically - you'll need to use Wayne's tool, global error handler.

You do mention the form though, thankfully you have some assistance on that score. Given that it is an object (not a module) then you can determine its name by using the CodeContextObject object.
e.g.
CodeContextObject.Name

Partway there. No cigar.

Cheers.
 
Thanks Leigh - after much research, I did come to that conclusion so I came up with a bit of a workaround.

I have checked out mztools and will try to spend some time with it in the near future. Thanks for the tip.

The link to 'Wayne's tool' didn't work.

Is there a benefit to using the CodeContextObject rather than the Form object?

Thanks again.
ML
 
I've got a function that's dependent on the form it's called from - if you declare
Code:
varname as access.form
as one of the arguments, you can then put "Me" when calling the function, then you can use it in the function as you will.
 
Passing a form object reference is another way of achieving the result.
But this, again, requires a function set up to do so. We're not achiving true global error handling - it's just centralised error handling.

The advantage of CodeContextObject is that it doesn't require context. It can be centralised, without being passed (you don't pass a form object or a form name etc to the error procedure).

Sorry about the link before. I'd tried to edit it to be abbreviated. We'll just go with the full thing this time.
www.everythingaccess.com/simplyvba-global-error-handler.htm

Cheers
 

Users who are viewing this thread

Back
Top Bottom