Error Trapping

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?
 
D

Dirk Goldgar

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top