Discussion Locked

Dates Validation in Access 2000

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

When I enter a date Ej. (33/33/2003) in a text field "Formatted as Short Date" in a form. I received the system error.
I want to be able to eliminate the system error and make a Custom error message. I have try to make a sub procedure in VB and place it in the method "Before update, After update, on focus, on lost focus ..." but nothing works.
Access detects the error before leave the text field and don?t pass control to the procedure in order to detect the error. Giving me the system error.
What can I do too make access pass control to the VB Sub form to validate the error.
Please gave me an example of the validation code that I cut use.

4 replies

by ntproenca

I never do it as you describe because of that problem.
Leave the text field as text on the form.
Do the following on the lost focus event:
If IsDate(textfield.text) then
table.field = CDate(textfield.text)
else
msgbox("invalid date")
textfield.setfocus
endif

Comments:
IsDate gets the date format from the system control pannel. If the function validates the input as a valid date then you can put the value in the database field with confidence.

This discussion is closed to new replies.