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 ????
Select Case Err.Number
Case 3021
msgbox "Cannot Add Record"
Case 3022
msgbox "Duplicate Record"
resume next
Else
End Select
Resume Test1_Exit
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.