Unfriendly error message in date field

G

Guest

I have a text box on a form bound to a field in a table. The data type for
the field is medium date. When a user enters something in the text box other
than a date the error message, "The value you entered isn't valid for this
field." appears. Is there a way to trap this error and replace a more
friendly one ( to tell the user to enter a date). I have tried validation
rules in the table, field as well as capturing the input during various
events for the textbox (Exit, before update, lostfocus, change, etc.), but I
cannot get in front of that error message. Any ideas? Thanks in advance.
 
G

Guest

Hi there!

I don't think there is much you can do if the form is directly tied to the
database. It does it's own validation and therefore you are not able to
control the error messages it produces. I think you've tried everything I
would have tried. Maybe one that you have already tried but on the data tab
in the properties window you have a validation message area also. Try that
one otherwise you will have to disconnect from the underlying table and then
capture the error with your own error message wording.
 
F

fredg

I have a text box on a form bound to a field in a table. The data type for
the field is medium date. When a user enters something in the text box other
than a date the error message, "The value you entered isn't valid for this
field." appears. Is there a way to trap this error and replace a more
friendly one ( to tell the user to enter a date). I have tried validation
rules in the table, field as well as capturing the input during various
events for the textbox (Exit, before update, lostfocus, change, etc.), but I
cannot get in front of that error message. Any ideas? Thanks in advance.

Place the following code in the Form's Error event:

If DataErr = 2113 Then
MsgBox "This is a friendly reminder to enter a valid date."
Response = acDataErrContinue
Else
Response = acDataErrDisplay
End If
 
W

Wayne Morgan

Use the form's Error event.

Example:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Debug.Print Me.ActiveControl.Name
If DataErr = 2113 And Me.ActiveControl.Name = "txtField2" Then
MsgBox "Error Number: " & DataErr & vbCrLf & "Please enter a date!",
vbOKOnly + vbExclamation, "Invalid Entry"
Response = acDataErrContinue
End If
End Sub

The error number you are after is 2113.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top