How to: Retrieve Information from an Error Object
When a run-time error occurs, the properties of the Err object are filled with information that uniquely identifies the error and information that can be used to handle the error.
The Err object's properties are reset to zero or zero-length strings ("") after an On Error Resume Next statement and after an Exit Sub or Exit Function statement within an error-handling routine. The Clear method can be used to explicitly reset Err.
Note
The options available in dialog boxes, and the names and locations of menu commands you see, might differ from what is described in Help depending on your active settings or edition. This Help page was written with General Development Settings in mind. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.
To retrieve information from an error object
You can filter for specific errors. This example checks to see if the error is a FileNotFound error and reacts if it is.
If Err.Number = 53 Then MsgBox("File Not Found") End If
You can also examine specific properties of the error object, such as Description, Erl, HelpContext, Helpfile, LastDLLError, Number, and Source. This example displays the description in a message box.
MsgBox(Err.Description)
See Also
Concepts
Choosing When to Use Structured and Unstructured Exception Handling
Reference
Description Property (Err Object)
HelpContext Property (Err Object)
HelpFile Property (Err Object)