-
Error handling
Hi,
I'm using an error handler in my code
Code:
Private Sub Sampcode()
On error goto procerror
other code
other code
other code
procerror:
MsgBox ("error message sample")
Now when I enter correct values, the error handler runs again! I want it to check again if my values are correct.
-
Re: Error handling
this is typically how it goes:
Code:
Private Sub SoSomething()
On Error GoTo errHandler
'Do some stuff that may cause an error
Exit Sub 'Exit the sub before falling into the error handler
errHandler:
'Handle the error here
End Sub
Alternatively....
Code:
Private Sub SoSomething()
On Error GoTo errHandler
'Do some stuff that may cause an error
DoCleanup:
' Do stuff to clean up before exiting
Exit Sub 'Exit the sub before falling into the error handler
errHandler:
'Handle the error here
Resume DoCleanup 'resume at the cleanup before exiting
End Sub
-tg
-
Re: Error handling
also very important... turn off the error handling with On Error GoTo 0
Code:
Private Sub SoSomething()
On Error GoTo errHandler
'Do some stuff that may cause an error
On Error GoTo 0
'Do some stuff that you don't want to test for an error
Exit Sub 'Exit the sub before falling into the error handler
errHandler:
'Handle the error here
End Sub