Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OnErrorResumeNext 2

Status
Not open for further replies.

dbero

Technical User
Mar 31, 2005
109
US
Although I try to limit my use of OnErrorResumeNext, times it is necessary. However, once I use it, I have never figured out to essentially turn the command off and revert back to normal. Does anybody know how to turn OnErrorResumeNext off within a procedure?

thank you
 
Two possible ways

On Error GoTo 0
Turns off all error trapping

On Error GoTo SomeLabel
Redirects execution to the statement following the label SomeLabel
 
Why not just comment the line out?

Have fun! :eek:)

Alex Middleton
 
My standard error-handling goes like this:

Code:
Sub SomeRoutine()
On Error Goto Sub_Error

    'Do stuff here

Sub_Exit:
On Error Resume Next
    'cleanup code here

    'e.g.:
    'rs.Close
    'Set rs = Nothing
    
    'also another common thing I do
    'DoCmd.SetWarnings True

    Exit Sub

Sub_Error:
    Msgbox "Error: " & err.number & " " & err.description
    Resume Sub_Exit
End Sub


On Error Goto 0 is only useful to me when I want to re-throw an error. If you get into lots of that sort of code, it's ... probably time to rethink your procedure structure. Anyway, that's my opinion; the bottom line is that it works, right?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top