How To Programmatically Set A Procedure Name To A String Variable

  • Thread starter CrazyAccessProgrammer
  • Start date
C

CrazyAccessProgrammer

I'm trying to centralize error messages using a function for displaying error
messages. I'd like to pass the name of the procedure where the error occurs
to this function that will display error messages so that the message box can
include the name of the procedure where the error occured.

I've tried using the ProcOfLine method but that method requires you to use
an argument where you explicitly state a line number in the VBA editor and
whereever that line number happens to fall is the name of the procedure that
ProcOfLine method will return.

That would work except that I'm constantly adding code to modules and as
such it would create more work constantly reviewing all the Subs and
Functions ProcOfLine calls to see if they still have the correct line number
argument every time I add code to the module.

What I really need to know is if there's a simple VBA function that simply
returns the string of the name of the procedure from which it's called.

In my imaginary VBA world it would look something like this:

Sub MySubThatDoesSomething

Dim MyProcName as string

MyProcName = SomeVBAFunction

(SomeVBAFunction would then set my string variable MyProcName to
'MySubThatDoesSomething')

End Sub

God I hope this makes sense to someone out there.
 
D

dymondjack

Check out www.mztools.com

Its a free addin that handles all sorts of this stuff for you. Setup custom
procedure/module headers and error handlers (including variables such as the
procedure name, type, etc). I'd be lost without it.

What you are trying to do through code is not easily accomplished at all,
that I know of.

mztools is definately the way to go here...

--
Jack Leach
www.tristatemachine.com

- "First, get your information. Then, you can distort it at your leisure."
- Mark Twain
 

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