On Error Statement
Enables an error-handling routine and specifies the location of the routine within a procedure; can also be used
to disable an error-handling routine.
On Error GoTo line
On Error Resume Next
On Error GoTo 0
The On Error statement syntax can have any of the following forms:
|On Error GoTo line||Enables the error-handling routine that starts at line specified in the required line argument. The line argument is any line label or line number. If a run-time error occurs, control branches to line, making the error handler active. The specified line must be in the same procedure as the On Error statement Otherwise, a compile-time error occurs.|
|On Error Resume Next||Specifies that when a run-time error occurs, control goes to the statement immediately following the statement where the error occurred where execution continues. Use this form rather than On Error GoTo when accessing objects.|
|On Error GoTo 0||Disables any enabled error handler in the current procedure.|
If you don’t use an On Error statement, any run-time error that occurs is fatal; that is, an error message is
displayed and execution stops.
Resume, Resume Next, Resume Line ()
Resumes execution after an error-handling routine is finished.
The Resume statement syntax can have any of the following forms:
|Resume||If the error occurred in the same procedure as the error handler, execution resumes with the statement that caused the error. If the error occurred in a called procedure,execution resumes at the statement that last called out of the procedure containing the|
|Resume Next||If the error occurred in the same procedure as the error handler, execution with the statement immediately following the statement that caused the error. If the error occurred in a called procedure, execution resumes with the statement immediately following the statement that last called out of the|
|Resume line||Execution resumes at line specified in the required line argument. The line argument is a line label or line number and must be in the same procedure as the error handler|
If you use a Resume statement anywhere except in an error-handling routine, an error occurs.
On Error GoTo Error
Simulates the occurrence of an error.
Syntax: Error errornumber
The required errornumber can be any valid error number.
The Error statement is supported for backward compatibility. In new code, especially when creating objects,
use the Err object’s Raise method to generate run-time errors.