14-10-2007, 07:56 PM
On Error Resume Next pretty much says to just push all errors into the Err object, but keep executing the statements (don't break execution) no matter what.
On Error Goto 0 turns this state off and returns the error-handling to it's regular (if something happens, shut everything down and complain a lot) state.
Also, error handling is local for every subroutine. If you put On Error Resume Next at the top of the sub, there is an implied On Error Goto 0 as soon as program execution leaves that subroutine (whether by returning a value, or by hitting an Exit Function, Exit Sub, End Function, or End Sub).
The code that Spodi posted will make sure that the single line of code you put between the statements will be run no matter what, and if there is an error, it'll simply be logged in the Err object and then ignored.
VB has pretty weak error handling, in my opinion. All you can really do is On Error Resume Next or On Error Goto Label, and just use If Err.Number > 0 Then to check if there even was an error.
On Error Goto 0 turns this state off and returns the error-handling to it's regular (if something happens, shut everything down and complain a lot) state.
Also, error handling is local for every subroutine. If you put On Error Resume Next at the top of the sub, there is an implied On Error Goto 0 as soon as program execution leaves that subroutine (whether by returning a value, or by hitting an Exit Function, Exit Sub, End Function, or End Sub).
The code that Spodi posted will make sure that the single line of code you put between the statements will be run no matter what, and if there is an error, it'll simply be logged in the Err object and then ignored.
VB has pretty weak error handling, in my opinion. All you can really do is On Error Resume Next or On Error Goto Label, and just use If Err.Number > 0 Then to check if there even was an error.