| On Error Statement |
Syntax 1
On Error GoTo label|0
label
Use: Either label or 0 is required
A valid label within the subroutine.
Syntax 2
On Error Resume Next
Description
Enables or disables error handling within a procedure. If you don't use an On Error statement in your procedure, or if you have explicitly switched off error handling, the Visual Basic runtime engine handles the error automatically. First, it displays a dialog containing the standard text of the error message, something many users are likely to find incomprehensible. Second, it terminates the application, so any error that occurs in the procedure produces a fatal runtime error.
Rules at a Glance
Syntax 1
The argument disables error handling within the procedure until the next On Error statement is executed.
The label argument specifies the name of the label defining an error-handling routine within the current procedure that will be branched to should an error occur.
A subroutine label must be suffixed with a colon; furthermore, you can't use a VB, reserved word for a subroutine label name. For example:
someroutine:
label must be in the same procedure as the On Error statement.
Syntax 2
When a runtime error occurs, program execution continues with the program line following the line that generated the error.
Programming Tips and Gotchas
If you have no error handling in your procedure or if error handling is disabled, the VB runtime engine traces back through the call stack until a procedure is reached where ...