Capturing Errors

  • Thread starter Thread starter sh0t2bts
  • Start date Start date
S

sh0t2bts

Hi All,

How do I capture an error?

I know I can write "on error goto Error_Handling"

But how do I find out what the error is?

Depending on the error I want my code to do diffrent things.


Cheers

Mark
 
Look at the properties of the error object, specifically Err.Number and Err.Description.

The following is taken from VBA Help for the On Error statement:

"Error-handling routines rely on the value in the Number property of the Err object to determine
the cause of the error. The error-handling routine should test or save relevant property values
in the Err object before any other error can occur or before a procedure that might cause an
error is called. The property values in the Err object reflect only the most recent error. The
error message associated with Err.Number is contained in Err.Description."
 
Take a look at the Err object in VBA Help. One way:

ErrorHandler:
If Err.Number = x Then
'do thing1
ElseIf Err.Number = y Then
'do thing2
End If
Resume Next
 
Back
Top