Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capture Event Name in Error Handler

Status
Not open for further replies.

annie52

Technical User
Mar 13, 2009
164
US
I have a standard module with the error handler I use most often. Is there some way to capture the event that caused the error and display that name in my message box?
 
Annie,

The following basic structure will work for you. It can be used for event prodedures, functions or subs. Note that you will have to hard code each procedure name ("fErrorMsg" for example)into the message. You can paste the entire function into a module and call it to see how the error handler works.

Also you can create more elaborate error handling routines and do things such as post errors to an error log.

Code:
Private Sub fErrorMsg()
On Error GoTo Err_Handler
Dim i As Integer
    i = Null    'to raise an error
    
Exit Sub
Err_Handler:
MsgBox "fErrorMsg: (#" & Err.Number & ") " & Err.Description
End Sub

Cheers, Bill
 
The closest I have ever got to doing this is creating a module level variable at the top of every module that has the name in it:
Code:
Private Const MODULE_NAME = "frmMain"

It's not automatic, but at least it makes my code look consistent, and I don't have to remember the name of the form/module I am in, since I know that MODULE_NAME will have it.
 
Hi everyone. I am not ungrateful for your replies and have not been ignoring you.

I've always used message boxes to display the error number and a better worded description. I was hoping to pass a variable (MyEventName) to the error handler I have in a standard module. I need some more time to learn about constants and exactly how to use them. I never learned the differences of module vs procedure level. Once I get this, I'll try the suggestion.

Duane, I'm not authorized to download or install software. And, it's doubtful the IT folks would make an exception. Good idea, though.
 
Duane, I'm not authorized to download or install software. And, it's doubtful the IT folks would make an exception. Good idea, though. "

Too bad, it is a very good productivity tool for Access developers and is FREE. I use it too, to do all of my error handling and it does put the name of the sub or function into the error handler. It is great and there are a ton of other tools it has available. I would try making a case with your IT folks/Boss around trying to get this one. MZ-Tools - don't leave home without it.

Bob Larson
Free Access Tutorials and Samples:
 
Hi Bob and Duane. I appreciate the feedback and additional info. I'll take a chance with the IT folks and see what happens.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top