A Quick and Easy Error Handler

By | 2002-06-01

In just a few easy lines you can a have a easy, error proof error handler for you apps! Plus, NO APIs!

Original Author: Erik Hagendorn

Code

''''IN MODULE!''''
Sub ErrHandler
ErrDesc = Err.Description
ErrNum = Err.Number
Beep
MsgBox "Error number " & ErrNum & " has occured because: " &_
ErrDesc, vbCritical, "Error"
Exit Sub
'Edit the msgbox all ya want to make it fit your needs
End Sub
'Ok, now to make my error handler work you need to
'add this right under the Sub...Examle:
Private Sub Command1_Click ()
'Now Here Is the code you need to add:
On Error Goto ErrHandle:
'Then put ALL your code for this Sub in as you would
'as usual, then at the end type:
ErrHandle:
Call ErrHandler
'AND THATS IT!
End Sub

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.