On error option -resume or end

merry_fay

Registered User.
Local time
Today, 15:03
Joined
Aug 10, 2010
Messages
54
Hi,

I'm running a vba loop to import a list of tables.

Assuming the end user has had a blonde moment & forgotten to untick one of the tables in the appropriate form & so the loop comes to a table which isn't there & so an error.
In some circumstances, it may need to be there, & so stopping the code (which is going to be a huge process) would be good, other times it's just, as above, an oversight, & so it would be good & a more user friendly proceedure to just continue & not to have to re-start!

What I want is to say:

On Error GoTo Err_Handler

Err_Handler:
If MsgBox ("Table " & NAME " not found. Continue?",vbYesNo)=vbNo Then
Exit Sub
Else
Continue from where it left off..... (post error of course)
End If

How do I get it to jump back into the loop?

Thanks
merry_fay
 
I think the real problem is why users are importing tables at all.

Maybe more information is required.

Chris.
 
what you need is a label, probably at the bottom of the loop - where you have the "next" statement that iterates the loop

then in the error handler you need a RESUME statement to return to the label. Note that you need to reactivate your error handler at the top of the loop (on error goto err_handler) or the next error will be unhandled.

Note also that you MUST use RESUME mylabel, not just GOTO mylabel - if you use GOTO, then the error handler is STILL active, and further errors will not be intercepted.


Err_Handler:
If MsgBox ("Table " & NAME " not found. Continue?",vbYesNo)=vbNo Then
Exit Sub
Else
Continue from where it left off..... (post error of course)
RESUME mylabel
{NB - not GOTO mylabel}
End If
 

Users who are viewing this thread

Back
Top Bottom