Error Handling Code not Handling Error [RESOLVED]
I am getting some weirdness with my error handling code and I am wondering if anyone can point out what I am doing wrong:
VB Code:
Private Sub Form_Load()
On Error GoTo errhandler
Dim x As Integer
Dim i As Integer
For i = 0 To 10
x = i / 0
retry:
Next
errhandler:
MsgBox "Error"
Err.Clear
GoTo retry
End Sub
The first time it runs we see the error message box. The second time it runs, we get the Run Time Error dialog box. Am I just missing something obvious? I tried putting another on Error Goto after the retry label, but that did not work.
Re: Error Handling Code not Handling Error
Got it, just a monday morning brainfart.
I had to do a resume next not a goto in my error handler. The goto kept us in the scope of the error handler.
Re: Error Handling Code not Handling Error
You MUST put an "Exit Sub" between the last main code line and the errorhandler label.
Mike