Databases Reference
In-Depth Information
On Error GoTo 0
turns off any previous On Error GoTo label statements. Any error occurring
subsequently will be handled by VBA in its own inimitable way.
12.5.6 The On Error Resume Next Statement
The syntax:
On Error Resume Next
tells VBA to continue executing the code immediately following the line that caused the
error. There are two important uses for this form of On Error . The first is to cause VBA
to ignore an error. For instance, the code:
Sub example( )
On Error Resume Next
MsgBox rs.RecordCount
End Sub
will report the record count when rs is a valid recordset and do nothing otherwise.
Another important use for the On Error Resume Next syntax is for in-line error checking ,
where we check for errors immediately following the line that may have caused an error.
For instance, another way to handle errors in the RecordCount property is as follows:
Sub example( )
On Error Resume Next
MsgBox rs.RecordCount
If Err.Number <> 0 Then
' code to handle error here
End If
End Sub
12.5.7 The Resume Statement
It is also possible to include the Resume statement in the error-handling portion of the
code. This will cause VBA to resume execution at the line that follows the one that
caused the error. Thus, the previous code is equivalent to the following:
Sub example( )
On Error GoTo ERR_EXAMPLE
MsgBox rs.RecordCount
Search WWH ::




Custom Search