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

Error handler for a Input Mask 1

Status
Not open for further replies.

Sylv4n

Technical User
Feb 27, 2002
83
GB
I have a date input mask on a field and if yo dont enter information that correspons to the input mask date then it gives a error message say something like

Cant save now field is not compliant with 99/99/00

I want to keep the input mask there but change the error message, I could use, ON ERROR GOTO ABC and then in ABC say IF err.number = (the error number) THEN msgbox "ABC"
but I cant get the number becouse it does not show me the code where it runs the err.discription

I also have a combo box that I have selected 'LIMIT TO LIST' and this does not allow them to enter anything new, but if they do try I want to have a cutom message that asks them if they are sure if they want to add that new one in or not,

I hope I have made myself partly clear :)
 
For question 1 you could use something like this:
Private Sub Form_Error(DataErr As Integer, Response As Integer)

If DataErr = 2279 Then 'incorrect date input for date mask
Response = 0 'prevent Access from displaying the canned message
MsgBox ("Please enter dates as 'mm/dd/yy', 'mmddyy', 'mm/dd/yyyy', or 'mmddyyyy'." & vbCrLf & vbCrLf & "Enter time as 24 hour format, e.g. '0930' or '1530'"), vbOKOnly, "Data format error."
End If

End Sub

On question 2, one approach would be to put in the NotInList property the following:

If msgbox ("Would you like to added this item to the list?",_
vbYesNo + vbQuestion, "Item not in list") = vbYes Then
Response = AddToList("Categories", "CategoryName", NewData)
Else
Response = acDataErrDisplay
Endif

This is from Access Inventory app sample - there are other samples around and it depends whether you want to add more than one field to a table, etc. Search Access Help, Access Samples, Microsoft web-based KnowledgeBase, and various Web sites - you will find more.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top