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

help with errors!

Status
Not open for further replies.

Luis939

MIS
Feb 28, 2003
453
US
in reference to thread707-521563 code that i was given was helpful, but it turned off VBA's ability to catch any error, is there anyway i can do the same thing as was asked in this thread, but just for one specific error that i can catch and put an msgbox, but have vba catch all other errors the same way it does, thanks!!
 
i should have clarified what i said, i have this code that i got from my past thread

Sub main()

On Error GoTo ErrH

Cells.Find (<insert find code here>)

Exit Sub

ErrH:

Select Case Err.Number
Case 123
MsgBox &quot;Blah, blah&quot;
Case 456
MsgBox &quot;Blah, blah, blah&quot;
Case Else
MsgBox &quot;No Error, but I thought I'd let you know&quot;
End Select

End Sub

but the thing is, that code will disable VBAs ability to tell you what the exact error is, this code allows you to do whatever you want in case you get an error, but you have to acccount for all possible errors you may encounter, I want to be able to just isolate one error (run time error 9) and put a message box, and let VBA handle all other errors, i hope thats clear to everyone, if its not please let me know, thank you all!!!
 
yea thats a simpler way of doing the same thing that i posted before, but that occurs whenever you get any error, i just wanted to do the same thing u did, but for just one specific error, so if error 9 happens, then i put that msg box by employing your code, but if there is any other kind of error, then i dont want that code to be activated, i just want to get the normal msg box VBA gives you
 
True, but its not a big deal, thanks any Skip!!!!
 
Hi 4335,

You may not want to do this, but you can check for your own error and then, if there was a different error, turn off your error handler and execute the statement which causes the error again, this time letting VBA catch it. With your code:

Code:
Sub main()

On Error GoTo ErrH

Cells.Find (<insert find code here>)

Exit Sub

ErrH:

Select Case Err.Number
Case 123
    MsgBox &quot;This is the error I want to catch&quot;
Case Else
Code:
    On Error GoTo 0
    Resume
Code:
End Select

End Sub

Enjoy,
Tony
 
yea i was thinking that there should be a way of equally switching back to having VBA handle those errors, but what does &quot;Goto 0&quot; do??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top