Capturing Errors

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
 
M

Myrna Larson

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."
 
J

J.E. McGimpsey

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top