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!

How to change error msg for invalid input mask 1

Status
Not open for further replies.

srast

MIS
Nov 11, 2002
42
US
Hello all.
Is there a way to change the error message which Access gives you when a user enters data into a table (or form) that doesn't conform to the input mask?
The message "The value you entered isn't appropriate for the input mask 'whatever' " doesn't mean anything to a user who isn't familiar with Access.
Any help would be greatly appreciated.
Steve
 
Hi,

To get the general format for error message control - paint a command button and then look at it's error control code.

This is how you can intercept errors from any control.

Copy and paste all of this and then where it says:
MsgBox Err.Description

say: msgbox "My particular error message".
i.e. replace Err.Description with above.

It all depends on which event of which control.

Regards,

Darrylle "Never argue with an idiot, he'll bring you down to his level - then beat you with experience." AND "A pointer to a solution is better than the solution - you'll remember the solution via a pointer". darrylles@totalise.co.uk
 
You'll have to do some error handling at the form level to do this. I can't think of a way to do it at the table level - normally users would not have direct access to tables anyway, right?

Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
  If DataErr = 2279 Then
    Select Case Screen.ActiveControl.Name
      Case "txtDate"
        MsgBox "Please enter the date using MM/DD/YYYY format!", _
            vbInformation, "Invalid Format"
        Response = acDataErrContinue
      Case Else
        MsgBox "The data you entered is improperly formatted.", _
            vbInformation, "Invalid Format"
        Response = acDataErrContinue
    End Select
  End If
End Sub
VBSlammer
redinvader3walking.gif

Unemployed in Houston, Texas
 
VBslammer:
Thanks for your reply.
Two difficulties I am encontering.
1) Shouldn't the input mask I have for the field in the table carry through to the form? It isn't.
2) Even though your code catches the error, after I close the custom message box, I still get the Access error Msgbox,"The value you entered isn't appropriate for the input mask ...". Why is that, and how do I stop it from happening?

Thanks again.
Steve
 
The following line tells Access not to show the built-in error message:
Code:
Response = acDataErrContinue

To show the built-in message use:
Code:
Response = acDataErrDisplay

The controls on your form will inherit field properties from the table if you drag them onto your form. VBSlammer
redinvader3walking.gif

Unemployed in Houston, Texas
 
Hi srast, temporarily rem (') out VBslammers code,

Put this on another line:

MsgBox DataErr

Type in something the mask will not accept, i.e. cause an error. This will give you the error no. I think it should be 2113 not 2279, maybe this was just an example. Also customise the message to suit your requirements.

Unrem (') VBslammer's code and replace with the error code displayed by the MsgBox. If it works give VBslammer a star because he did the leg work and deserves one.
 
VBslammer: I really appreciate your reply. I hadn't noticed the line "Response = acDataErrContinue" that was in the original code you posted. It's working great!

billpower: Error 2113 is when the data you entered doesn't match the field type, I believe. (not when it doesn't fit the input mask).
At any rate, error 2279 catches the errors perfectly.
Also, you can use the AccessError function, and use a String, to see the Error description.
Dim strErr As String
strErr = AccessError(DataErr)
Debug.Print strErr

Thanks.
Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top