|
|

Trapping Input Mask Errors
Whilst using Input Masks on certain types of data is a good idea, in order for your application to be helpful to the user, if the data entered does not meet the requirements of the input mask, then Access displays an error. In this case, you shopuld trap the error, and display a meaningful message to the user:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Select Case DataErr
Case 2279
Select Case Me.ActiveControl.Name
Case "txtPostalCode"
MsgBox "The data that you have entered is not in the correct format, such as 'BT51 0LL'." & vbCrLf & vbCrLf & "Please re-enter the data in the correct format.", vbExclamation + vbOKOnly, " "
Response = acDataErrContinue
End Select
End Select
End Sub
|
Also, you must be prepared for them entering in information that meets the requirements of the input mask, but is nonsensical, such as entering in "55:55" for a time. In this case, you should alert the user to the error, and force them to correct the mistake before continuing.
The way to do this is to trap the error on the form as shown below, which deals with two text boxes that have input masks:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Select Case DataErr
Case 2113
Select Case Me.ActiveControl.Name
Case "txtDepartTime"
MsgBox "The time that you have entered is not valid." & vbCrLf & vbCrLf & "Please re-enter.", vbExclamation + vbOKOnly, " "
Response = acDataErrContinue
Case "txtDepartDate"
MsgBox "The date that you have entered is not valid." & vbCrLf & vbCrLf & "Please re-enter.", vbExclamation + vbOKOnly, " "
Response = acDataErrContinue
End Select
End Select
End Sub
|
Obviously, the two methods above can be combined into the same procedure, firstly to trap for data that is entered that does not match the Input Mask, and secondly to trap for data that is invalid.
Top
HOME |
NEW |
TABLES |
QUERIES |
FORMS |
REPORTS |
GENERAL |
API |
DOWNLOADS |
TUTORIAL |
RESOURCES
E-MAIL
Copyright & Disclaimer
| |
|