You forgot to exit the Sub if there was no error. Just add an Exit Sub
before the error handling code.
Public Sub GetData()
On Error GoTo MyHandler
With myObject
msgbox "test"
'- - -- - more code here etc..
End With
Exit Sub ' ** add this here **
MyHandler:
MsgBox "error"
end sub
If you're using VB.NET you should *really* consider switching to structured
error handling using try/catch/finally blocks. If you decided to do this
your code would be changed to:
Public Sub GetData()
Try
With myObject
MsgBox "test"
'- - -- - more code here etc..
End With
Catch ex As Exception
MsgBox "Error: " & ex.Message
End Try
End Sub
--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
"anonymous" <an*******@discussions.microsoft.com> wrote in message
news:D7**********************************@microsof t.com...
Can someone help me? I have an error handler that is not working correct.
Below is a snippet, for some reason it read through, all the way to the
error handler though there is not one. Thanks.
Public Sub GetData()
On Error GoTo MyHandler
With myObject
msgbox "test"
'- - -- - more code here etc..
End With
MyHandler:
MsgBox "error"
end sub