×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Simple Error hadling
2

Simple Error hadling

Simple Error hadling

(OP)
I have a simple Sub with an Error Handler:

CODE

Private Sub Test()

On Error GoTo ErrorHandler
...

Exit Sub
ErrorHandler:
'Deal with the error

End Sub 

The program generates a few errors, but only first one goes to the ErrorHandler, the rest just display the message in VBA IDE about the error.

I don't have anywhere On Error GoTo 0 or anything.
I did try all setting options in Tools - Options... - General tab - Error Trapping frame

How do I trap all errors, not just the first one? ponder

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: Simple Error hadling

Hi,

Resume

CODE

Private Sub Test()

On Error GoTo ErrorHandler
...

Exit Sub
ErrorHandler:
'Deal with the error
Resume
End Sub 

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

RE: Simple Error hadling

In Skip's code - you can use Resume or Resume Next, depending to which line you plan to return.

combo

RE: Simple Error hadling

(OP)
Actually, the code I have is to validate data against my data base, so the errors are in the dynamically created Select statements. When that happens, I wanted to use a GoTo (even though I don't like using GoTo's) and go to a code label:

CODE

Private Sub Test()

On Error GoTo ErrorHandler
...
ThePlace:
...
Exit Sub
ErrorHandler:
'Deal with the error
GoTo ThePlace

End Sub 

That's why Resume or Resume Next would not work because I don't want to re-execute the line of code that created the error, or execute next line of code. I want to 'jump' (GoTo) somewhere else in the code.

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: Simple Error hadling

2
The same (almost), no GoTo: GoTo ThePlace Resume ThePlace smile

combo

RE: Simple Error hadling

(OP)
Thanks combo
I always used Resume or Resume Next, but never Resume [label] and I didn't even know about it.

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: Simple Error hadling

It allows to exit error handling part of procedure and continue (a good article by Chip Pearson).

combo

RE: Simple Error hadling

You can also reset the error handling:

CODE --> VB

Private Sub Test()

On Error GoTo ErrorHandler
...
ThePlace:
...
On Error GoTo 0  'This allows errors to be handled 'up the stack'
Exit Sub
ErrorHandler:
'Deal with the error
Resume ThePlace

End Sub 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close