See Also Example
Resumes program execution after an error-handling routine is finished.
Syntax
Resume { [0] | Next | line}
Remarks
The various forms of the Resume statement redirect program flow as described below:
Statement Description
Resume [0] Program execution resumes with the statement that caused the error or at the most recently executed call out of the procedure containing the error-handling routine.
Resume Next Execution resumes with the statement immediately following the one that caused the error or with the statement immediately following the most recently executed call out of the procedure containing the error-handling routine.
Resume line Execution resumes at line, which is a line label or line number . The argument line must be in the same procedure as the error handler.
Where execution resumes is determined by the location of the error handler in which the error is trapped, not necessarily by the location of the error itself.
The following table summarizes where a program resumes execution when the Resume [0] statement is used:
Where error occurs Where program resumes
Same procedure as error handler Statement that caused the error
Different procedure from error handler Statement that last called out of the procedure containing the error handler
If you use a Resume statement anywhere except in an error-handling routine, an error occurs.
When an error-handling routine is active and the end of the procedure (an End Sub or End Function statement) is encountered before a Resume statement is executed, an error occurs because a logical error is presumed to have been made inadvertently. However, if an Exit Sub or Exit Function statement is encountered while an error handler is active, no error occurs because it is considered a deliberate redirection of program flow.
On Error Statement
Trappable Errors
The example uses Resume Next to end error handling in a procedure. To try this example, paste the code into the Declarations section of a form. Then press F5 and click the form.
Sub Form_Click ()
Dim Drive, Msg ' Declare variables.
On Error GoTo ErrorHandler ' Set up error handler.
Msg = "This demo attempts to open a file that does not exist on a "
Msg = Msg & "drive that may not exist. When the operation fails, "
Msg = Msg & "the ErrorHandler routine will display a message box "
Msg = Msg & "that indicates what error occurred."
MsgBox Msg ' Display opening message.
Drive = Chr(Int((26) * Rnd + 1) + 64) ' Make random drive letter.
Open Drive & ":\TEST\X.DAT" For Input As #1 ' Try to open file.
Close #1 ' Close the file.
Exit Sub ' Exit before entering
' error handler.
ErrorHandler: ' Error handler line label.
Select Case Err
Case 53: Msg = "ERROR 53: That file doesn't exist."
Case 68: Msg = "ERROR 68: Drive " & Drive & ": not available."
Case 76: Msg = "ERROR 76: That path doesn't exist."
Case Else: Msg = "ERROR " & Err & " occurred."
End Select
MsgBox Msg ' Display error message.
Resume Next ' Resume procedure.
End Sub