This is explained thoroughly in the VB6 manual under Error Handling Hierarchy. On Error Goto 0
disables the error handler in the current procedure, not in the procedures that called it.
If an error occurs in a procedure and
this procedure doesn't have an enabled
error handler, Visual Basic searches
backward through the pending
procedures in the calls list — and executes the first
enabled error handler it finds. If it
doesn't encounter an enabled error
handler anywhere in the calls list, it
presents a default unexpected error
message and halts execution.
As others have said, you can go to Tools-Options-General tab and choose Break on all errors. That effectively disables all your On Error statements - the IDE will break immediately on every error.
That can be irritating if your VB6 code throws errors as part of normal operation. For instance when you check whether a file exists, or when the user presses cancel in a common dialogue. You don't want the IDE to break every time on those lines. But you might have boilerplate error handlers in all your event handling procedures, to stop the program crashing out on unexpected errors. But they are a nuisance when you're debugging problems because the IDE doesn't break on the line with the error. One trick is to switch off those error handlers when running in the IDE, but keep them in the built executable. You do it like this.
Drop these functions into a module.
Public Function InIDE() As Boolean
Debug.Assert Not TestIDE(InIDE)
End Function
Private Function TestIDE(Test As Boolean) As Boolean
Test = True
End Function
Then you can write your error handlers like this.
Private Sub Form_Load()
If Not InIDE() Then On Error Goto PreventCrashes
<lots of code>
Exit Sub
PreventCrashes:
<report the error>
End Sub
Pinched from here. Another tip - use the free add-in MZTools to automatically add these boilerplate error handlers. For production-quality code, you could go further and put an error handler in every routine to create a ghetto stack trace. You might also log the errors immediately in every error handler.
EDIT: Ant has correctly pointed out that On Error Goto -1
is a VB.Net statement and isn't valid in VB6.
EDIT: Arvo and OneNerd have written answers with some interesting discussion of emulating Finally teardown blocks in VB6 error handling. The discussion in this question is also worth a look.