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

Error Handling 1

Status
Not open for further replies.

DummyForAccess

Technical User
Aug 7, 2002
38
0
0
US
Ugh, it's been a while. I can't for the life of me remember how to do two things:

Create a simple error handling routine inside a sub.


Once I do the above, need to create a little message box, probably just an okay button type.
 
at the beginning of the sub put the following...

On Error GoTo MyError





And at the end of the sub put this...

Exit Sub
MyError:

MsgBox "Error Number: " & Err.Number & "Error Description: " & Err.Description,vbinformation,"Error in This Sub..."
Err.Clear

You can also put... Resume Next after Err.Clear

Hope this helps...

LF

"As far as the laws of mathematics refer to reality, they are not certain; as far as they are certain, they do not refer to reality."--Albert Einstein
 
Thanks so much. I've got error handling in all of my macros now, it looks so much better for the user to get a message that makes sense to them rather than getting the VB "End, Debug" kind of message.
 
Yeah, You are right. I have been programming with Visual Basic for over two-years now and I just learned about this error handling about two weeks ago. I am not a programmer by trade so I didn't really have to worry about this stuff, but it sure is nice to know which sub is creating the error rather than going line-by-line through the whole code to find it. Anyway, I am glad that I could pass my newly learned information on!

LF

"As far as the laws of mathematics refer to reality, they are not certain; as far as they are certain, they do not refer to reality."--Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top