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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with error handler 1

Status
Not open for further replies.

Doteco

Programmer
Jan 9, 2005
16
AU

I have a loop (looping through records in a recordset) which has an "on error goto..." statement (in the loop) that deals with the error by skipping that record and moving on to the next... works OK for the first error that it comes accross but next time around it throws up an error message and totally ignores the "goto" bit.

Tried resetting it with a "goto 0" beforehand but it still trips up.

Any clues on how to resolve this?

Regards, Doug.
 

You probably need a Resume statement somewhere, hard to tell without more info. So can you post the relevant code?
 
Just worked it out !!

For those who are interested... "the on error goto oops" took me to the error handler outside of the loop - then if it was a particular type of error, control was sent back into the loop (just before the "next i" bit) to a label called "SkipIt:" - by putting "Resume Next" as the first line after "SkipIt" if a subsequent record generated the same error then the "the on error goto oops" line worked and control went to "oops" and then back to "SkipIt" in the loop ready to process the next record.

Clear as mud !

Can I give myself a "star" for this solution ?

Doug.
 
Thanks SonOfEmidec1100 - you were right but I didn't discover your post until I'd submitted my second one (we must have been replying at the same time) - though I did discover that "Resume" after "SkipIt:" just kept "Resuming" itself and the code would hang - whereas "ResumeNext" did the trick.

Regards, Doug.
 
Another technique is to use ON ERROR RESUME NEXT , along the lines of this example

Code:
    On Error Resume Next
     Statement that can cause Error
    If Err.Number <> 0 Then
       'error process if required
    End If
    'reset error handler
    On Error GoTo ErrorHandler
 
Yes, I can see how that would work... thanks again.

Doug.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top