Error Trapping

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Every time I try to run the following code I get "Compile Error Label not
defined"

Private Sub cmdShowDetails_Click()

On Error GoTo ErrorHandler

(Main body of code here)

CleanUpAndExit:
End Sub

ErrorHandler:
Call MsgBox("Invalid Part Number")
Resume CleanUpAndExit
End Sub

Any suggestions?
 
In
Josh Forand said:
Every time I try to run the following code I get "Compile Error
Label not defined"

Private Sub cmdShowDetails_Click()

On Error GoTo ErrorHandler

(Main body of code here)

CleanUpAndExit:
End Sub

ErrorHandler:
Call MsgBox("Invalid Part Number")
Resume CleanUpAndExit
End Sub

Any suggestions?


Your ErrorHandler code block has to be inside the Sub, but you've placed
it after an "End Sub" statement. Change that first "End Sub" to "Exit
Sub":

CleanUpAndExit:
Exit Sub
 
Back
Top