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

on error goto..

Status
Not open for further replies.

sunaj

Technical User
Feb 13, 2001
1,474
0
0
DK
Hi,

I have a program that read though a file and load the data into an database. Sometimes there's a problem in the file and and error is generated. I use 'on error goto' to deal with the error. When the user has dealt with the problem I jump to the begining of the function to start over agian.

The problem:
The first error is dealt with fine, but when the second error is generated (I use err.raise) it comes up with the error meassage instead of jumping to the error handler.

In the end of the errhandler I have: err.clear
In the begining of the function I have: on error goto

What's the problem?
Any help will be appreciated

Sunaj

This is an illustation of my function:

Function LoadFile
TryAgain:
on error goto ErrHndl
'lot of code here with some err.raise

errHndl:
'here I deal with the error
err.clear
if .. goto TryAgain (else end)
end function

 
Hi,

I've found the problem:

Use 'resume' instead of 'goto' when the error has been dealt with.

Thanks for checking my question anyway...
:cool:Sunaj
 
You could also call the Clear method of the Err object. But the resume is a better way to handle it.

Chip H.
 
hi
I have a similar situation.... i was debating between use of resume and resume next..coz my problem is i can not deal with error during a run of program.. my need is to write entry to a <b>log file</b> and resume....but if i resume w/ dealing with error, i get run time error...so i was thinking to use...resume next.
I was not aware about err.clear till i read this thread. Now i have a question...what is difference between doing <b>resume next </b> AND doing <b>err.clear resume</b> Please tell me in what book <b>or</b> where in MSDN can I read more about error handling?
Thank you,
pjani
 
In the MSDN Library, look under Microsoft Office for Building Applications with Microsoft Access. That's the most thorough documentation on writing error handlers.

BTW, there's no need to do Err.Clear before Resume. The Resume statement clears the error implicitly.

Also, in regard to Chip's post, Err.Clear followed by GoTo isn't the same as Resume. VB(A) keeps an internal flag that gets turned on when an error branches to an error handler, and turned off when a Resume, Exit/End Sub/Function, or On Error is executed. If the flag is on when an error occurs, VB will ignore the error handler at that level. This prevents errors within the error handler from causing a recursive entry and infinite loop. I'm pretty sure Err.Clear doesn't reset this flag, so Err.Clear followed by GoTo would leave the error handler disabled (which was Sunaj's original problem). Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top