By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,222 Members | 1,118 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,222 IT Pros & Developers. It's quick & easy.

On error goto

P: n/a
HDI
Hi,

I've got following code:

For each ....

on error goto errhand
errhand:
...

next

When the first error occures he handles errhand, correct.
when the second error occures access gives a global error and doen's
handle errhand.

Thx

Apr 28 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
> For each ....

on error goto errhand

errhand:
...
next

When the first error occures he handles errhand, correct.
when the second error occures access gives a global error and doen's
handle errhand.


It seems strange to me to find an "on error" statement inside a for cycle.

Anyway, why don't you post more code (e.g., the entire routine) so it would
be more simple to suggest?

--
PBsoft di Gabriele Bertolucci
www.pbsoft.it
skype: pbsoftsolution
Apr 28 '06 #2

P: n/a
PBsoft wrote:
For each ....

on error goto errhand

errhand:
...
next

When the first error occures he handles errhand, correct.
when the second error occures access gives a global error and doen's
handle errhand.


It seems strange to me to find an "on error" statement inside a for
cycle.

Anyway, why don't you post more code (e.g., the entire routine) so it
would be more simple to suggest?


Indeed, I have some crazy code but I've never nested an error handler like
that.
Apr 28 '06 #3

P: n/a
HDI wrote:
Hi,

I've got following code:

For each ....

on error goto errhand
errhand:
...

next


As the others have said, and I will say frankly, this is very bad practice.

Asjust your code like this:

On error goto errhand 'This should be at the START of your code!

For each....

next....

Exit_Proc:

Exit sub (or function)

Errhand:

Put your stuff here. If on a specific error you want to return to the
next or same line use resume or resume next. If you want to quit the
procedure, use resume exit_proc.

If you want to have different error routines for different parts of the
procedure, you can do this, but I won't submit how I do it, because IMO,
if you're writing code like the above, you need more experience.

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Apr 28 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.