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

Custom error messages - Can you trap Access ones as well?

Status
Not open for further replies.

ChemistZ

Programmer
Oct 30, 2001
70
US
I have Combo boxes that are set "Limit to List" and when someone types something that isn't in the list they get the standard error message from Access. Can I create a custome error message that will come up instead of the standard Access one? I know I CAN create one - I guess my real question is how to trap this particular occasion and set my own message to it. I also would like to create a custome message for the instance when someone types something other than what an input mask requires - that particular standard message is really bad. Can anyone help?
 
Yes, you trap Access errors. It's done all the time. All you need to know is the error number access generated. Here's an example.

Code:
Private Sub Add_New_Click()
On Error GoTo Err_Add_New_Click
    
    DoCmd.GoToRecord , , A_NEWREC

Exit_Add_New_Click:
    Exit Sub

Err_Add_New_Click:
    If Err = 2105 Then
       MsgBox "Duplicate record - information previously entered in database", vbCritical
   Else
       MsgBox Error$
   End If
   
    Resume Exit_Add_New_Click
    
End Sub
Maq B-)
<insert witty signature here>
 
Okay - how do you determine the error number generated for something like the message that comes up for Linit to List Combo box settings. It doesn't have a number on it.
 
Hmmm, All the errors that I've seen so far have had numbers displayed. You can get Access to display the number for you by replacing Msgbox Error$ with Msgbox err.number & &quot; &quot; & err.description in the above code.

If this particular error really doesn't have any number then you could trap based on the err.description instead. It's messier, but it should work. Maq B-)
<insert witty signature here>
 
Okay - I checked in help which errors are trappable and I am ticked off at Microsoft now. I saw the one for a Required field and several other types of errors that result from field properties changes but I saw nothing corresponding either to input masks or Limit to List Combo Boxes. For the err.description thing, I tried instead if err= 2105 : if err.description=&quot;The text you entered isn't an item in the list.&quot; However, the actual error message is two lines of text. any ideas?
 
Ok, I just checked the help file in Access. It seems that the &quot;error&quot; you're referring to isn't really an error in Access. (Go figure). Access helps states in the NotInList Event topic &quot;The NotInList event doesn't trigger the Error event.&quot;

You can add code to the NotInList event which will generate a custom msgbox, but in my database my custom msgbox came up as well as the standard error msgbox that you're seeing.
I couldn't figure out a way to suppress the standard box, but perhaps some other bright guru here knows a way. Maq B-)
<insert witty signature here>
 
Aha!! Got it!

Set response = -1 to suppress the msgbox. Maq B-)
<insert witty signature here>
 
You are amazing - I don't suppose you can come up with a way to fix input masks can you? See new post on Input Masks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top