Is SUB name available in a variable?

  • Thread starter Thread starter Brad
  • Start date Start date
B

Brad

I would like to develop a common error handling/error reporting technique.

Is there a way to programmatically obtain the name of the SUB that is
currently being executed? (Without stuffing it into a variable with a line
of code). I was hoping to find an environment variable or something along
these lines.

Thanks
Brad
 
Been there done that.

I ended up adding parameters to my global error handling that allows it to
capture the Module name and Function/Sub name that threw the error. The
Module name was needed in the event that two Sub are identically named such
as Detail_OnCurrent.

Why oh why isn't there an Err.CurrentModule and Err.CurrentProcedure
properties.
 
I have been using MZ-Tools for many years, but had not heard of SimplyVBA
Global Error Handler.
I had always believed that there was no way to accomplish what it does. Do
you know of any articles that explain how to get the call stack, etc.
 
No: I don't know how to get the call stack.

What I do is to put this in the General Declarations of every module:
Private Const conMod = "xxxx"
where xxxx represents the name of this module.

Then the error handler refers to conMod. Even if you cut'n'paste code
between modules, the name is reported correctly.
 
Thanks Allen,

I have been using MZ-Tools to add my error handlers and automatically
include the module and proc name, but I see the point of using a private
const.

Recently, I started collecting my own call stack info based on examples that
I found.
It is easy to include in new code using MZ-Tools templates, but not so easy
to add to existing code. It would sure be nice if it were somehow available
via VBA.
 
Why oh why isn't there an Err.CurrentModule and Err.CurrentProcedure

My exception handlers collect the line number where
the error happened: (I have to add line numbers), and
I use unique line numbers so that the line number is a
unique index.

But eventually the exception is raised to the top level,
which is a form, and forms do have a name. Classes
probably do have a name in general, so if you want
to automatically have the module name, you could try
using a class module.

(david)
 
Back
Top