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

Simple Error hadling 2

Status
Not open for further replies.

Andrzejek

Programmer
Jan 10, 2006
8,502
US
I have a simple Sub with an Error Handler:

Code:
Private Sub Test()

On Error GoTo ErrorHandler
...

Exit Sub
ErrorHandler:[green]
'Deal with the error[/green]

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 [tt]On Error GoTo 0[/tt] 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
 
Hi,

Resume
Code:
Private Sub Test()

On Error GoTo ErrorHandler
...

Exit Sub
ErrorHandler:
'Deal with the error
[b]Resume[/b]
End Sub

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
 
In Skip's code - you can use Resume or Resume Next, depending to which line you plan to return.

combo
 
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
...[blue]
ThePlace:[/blue]
...
Exit Sub
ErrorHandler:
'Deal with the error[blue]
GoTo ThePlace[/blue]

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
 
The same (almost), no GoTo: [tt]GoTo ThePlace Resume ThePlace[/tt] [smile]

combo
 
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
 
It allows to exit error handling part of procedure and continue (a good article by Chip Pearson).

combo
 
You can also reset the error handling:
Code:
Private Sub Test()

On Error GoTo ErrorHandler
...
ThePlace:
...
[COLOR=#3465A4][b]On Error GoTo 0[/b][/color]  'This allows errors to be handled 'up the stack'
Exit Sub
ErrorHandler:
'Deal with the error
Resume ThePlace

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top