Name of current Private Sub

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I am bringing in error reporting, when an error happens it emails me with
the Form Name, Err.Description, and I want the name of the Private Sub that
is running.

I can find Form Name and Err.Description easy but how do I find what the Sub
name is?

Or could I somehow find the control that has focus. But it is not always a
control or command button that is running code, for instance I have OnCurrent
running code.

Any ideas?

Many thanks

James
 
Perform, what is known as , "Push and Pop Stacks". Create the respective
functions (with the use of an array) that you can supply the subprocedure or
function name.

For example:

Private Sub Test()

' At the beginning of your subprocedure or function, call the Push()
Push("Test")

:
other code here
:


' At the end of your subprocedure or function, call the Pop()
Pop("Test")

End Sub


HTH

--
Rob Mastrostefano

FMS Professional Solutions Group
http://www.fmsinc.com/consulting

Software Tools for .NET, SQL Server, Visual Basic & Access
http://www.fmsinc.com
 
It looks like you need a universal error function or subroutine. I've read
about these but haven't had to use them (there's probably an article or two
on the web). The essential idea is that you create a function with arguments
that include the name of the subroutine calling it:

Sub myErrorRoutine(mySubName, myErr)
MsgBox myErr.Number & " " & myErr.Description & vbNewLine & "Error
happened in " & mySubName
End Sub

I've kept it simple but you could obviously use If/Then or Select/Case
statements to perform different actions depending on the error values and
which subroutine generated the error.

To use it, you call this subroutine from within every routine in your
project, e.g.

Sub Test()
....
Exit Sub
error_handler:
myErrorRoutine "Test", Err
End Sub
 
Back
Top