"On Error Resume Next" Question

J

Jim

when you put this line in the code, does it act for only
the next line or all lines after. If for the latter,is
there a reverse of the statement to stop it?
 
J

J.E. McGimpsey

Note: "all lines after" for the current procedure. If sub2 was
called from sub1, then exiting sub2 and returning to sub1 resets the
error handler to sub1's, or the default.

For instance:

Public Sub Sub1()
On Error GoTo A
Sub2
Err.Raise 1
Exit Sub
A:
MsgBox "A"
On Error GoTo 0
End Sub

Public Sub Sub2()
On Error GoTo B
Sub3
Err.Raise 2
Exit Sub
B:
MsgBox "B"
End Sub

Public Sub Sub3()
On Error GoTo C
Err.Raise 3
Exit Sub
C:
MsgBox "C"
On Error GoTo 0
End Sub

The On Error GoTo 0 in Sub3 doesn't affect Sub2's call to B:, and
Sub1's call to A: is not affected by sub2's call to B:.
 

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

Top