On Error Statements

You can use the "On Error" statement to specify what happens when an error occurs:
On Error Resume Next - Returns control to the statement following the one at which the error occurred
On Error Resume LineLabel - Returns control to a specified line label
On Error Resume [0] - Returns control to the statement at which the error occurred (statement is re-run)
On Error Goto LineLabel - Execution jumps to the line label when an error occurs
On Error Goto 0 - Resets the Err object and resets the Err.Number to zero.

On Error GoTo 0 
On Error GoTo LineLabel
On Error Resume Next

On ? GoSub statement ??

On Error GoTo -1

Clears the error handling allowing you to define another error trap.

Sub DoSomething() 
   On Error GoTo LineLabel1
   Err.Raise 9999, "My Error"
   Exit Sub

   On Error GoTo -1
   On Error GoTo LineLabel2
   Err.Raise 1000, "My Error"
   Exit Sub

End Sub

© 2020 Better Solutions Limited. All Rights Reserved. © 2020 Better Solutions Limited TopPrevNext