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

Error handling ????????

Status
Not open for further replies.

andrep

Technical User
Feb 27, 2002
40
CA
I have a sub with witch i need error handling!

Since i have many conditions which must be met, i need to use several message boxes. How does one handle this situation, can someone post an example with multiple error handling on the same sub ????

Thanks
 
Public Sub Test1()
On Error GoTo Test1_ERR

' Your code here...


Test1_Exit:
Exit Sub

Test1_ERR:

Select Case Err.Number
Case 3021
msgbox "Cannot Add Record"
Case 3022
msgbox "Duplicate Record"
resume next
Else
End Select
Resume Test1_Exit

End Sub
John Ruff - The Eternal Optimist :)
 
The easiest way, based on your rather brief desc would be to use if then loops and put the message boxes inside the loops:

if SomeVar="" then 'put any condition
msgbox("Please choose item")
me.txtSomeVar.setFocus
end if
if SomeOtherVar = "" then 'some other condition
msgbox("Please choose item")
me.txtSomeOtherVar.setFocus
end if

or change the message boxes to allow input directly in the box.

hth
Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
andrep,
I create a function in a standard module; i.e., Module1 which uses a select statement as listed above. While programming, I find error conditions which I have yet to trap. I add the condition to my function which returns a user friendly error message of my design. The advantage is that I call this function from all my error handling routines at the end of the sub. If I later need to change a message, I only have one place to go, not numerous forms and subroutines. I pass the error number to the function and return the custom message. Your error message are standard throughout your program. Mainly though, you don't have to keep writing the same message over and over.

mac
 
Thanks all,

Have a good view of my options now!

God bless !
André
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top