need a textbox control Validation event ...

B

Bill

Hello All,

Using AC2003.

I have a form with bound controls.
One of the textbox controls is bound to a date field.

When an invalid date is entered (i.e. 12/34/04 - no month has 34 days) and
you leave the field the built in access field validation pops a message that
says "The data you have entered is invalid for this field. "
I need way to check the value entered and do my own validation so I can give
my own more descriptive message to help the user enter the correct data.
How can I turn off the access validation or preferably is there a way I can
do my own validation before Access does?

I know about the validation rule and text property but that only seems to
allow simple expressions. Unless someone know of a valid expression that
can be used to check that a valid date is entered.

Any help is greatly appreciated.

Thanks,

Bill
 
A

Allan Murphy

Bill

Try this

You may have to change the message string to the date format for your
region.

I also use the YYYY format for year.

Private Sub Form_Error(DataErr As Integer, Response As Integer)

Dim strMsg As String


Const conErrinvalidformat = 2279 ' error number 2279 is generated when
' there is an invalid date format


If DataErr = conErrinvalidformat Then ' trap for error number 2279

' If error is due to an invalid date format,i.e. dd/mm/yy
' in lieu dd/mm/yyyy, display a message showing the user the correct
format.

strMsg = "The correct format is dd/mm/yyyy, " & _
" " & _
"the year must have four digits" & _
" " & _
"E.G. 1999 or 2000"
MsgBox strMsg
Response = acDataErrContinue
End If

End Sub
 
B

Bill

Allan One thing I noticed. I am getting a DataErr value of 2113 not
2279.

hmmm ??

Bill
 

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