Table of contents
Collapse the table of content
Expand the table of content

Error Statement

office 365 dev account|Last Updated: 6/12/2017
1 Contributor

Simulates the occurrence of an error.



The required errornumber can be any validerror number. Remarks The Error statement is supported for backward compatibility. In new code, especially when creating objects, use the Err object's Raise method to generaterun-time errors. If errornumber is defined, the Error statement calls the error handler after theproperties of Err object are assigned the following default values:

NumberValue specified as argument to Error statement. Can be any valid error number.
SourceName of the current Visual Basic project.
DescriptionString expression corresponding to the return value of the Error function for the specified Number, if this string exists. If the string doesn't exist, Description contains a zero-length string ("").
HelpFileThe fully qualified drive, path, and file name of the appropriate Visual Basic Help file.
HelpContextThe appropriate Visual Basic Help file context ID for the error corresponding to the Number property.

If no error handler exists or if none is enabled, an error message is created and displayed from the Err object properties.

Note Not all Visual Basic host applications can create objects. See your host application's documentation to determine whether it can createclasses and objects.


This example uses the Error statement to simulate error number 11.

On Error Resume Next ' Defer error handling. 
Error 11 ' Simulate the "Division by zero" error. 
© 2018 Microsoft