Date Validation and appropriate message

G

Guest

I have a text box on a form that has a control source of a date field set up
as short date with a mask of 00/00/0000 ( MS Access 2003 ).
If an invalid date such as 31/09/2005 is entered, the generic Access message
is displayed stating the field is invalid.
I want to display the massage 'Invalid date' and have tried to do this with
the validation rule of the field in table design with no success.

I tried to use the ISDATE() function in the expression builder , but I am
obviously doing something wrong as I can't get the expression builder syntax
correct, if indeed this is the correct way to do it!

Thank you.
 
G

Guest

Its always a mistake to have a user enter a date!
Dates should be selected from a calendar which only shows valid dates.
You will find this an infinitely better solution and one that you can use
over and over in different projects you work on.

Dorian
 
J

John Vinson

I have a text box on a form that has a control source of a date field set up
as short date with a mask of 00/00/0000 ( MS Access 2003 ).
If an invalid date such as 31/09/2005 is entered, the generic Access message
is displayed stating the field is invalid.
I want to display the massage 'Invalid date' and have tried to do this with
the validation rule of the field in table design with no success.

I tried to use the ISDATE() function in the expression builder , but I am
obviously doing something wrong as I can't get the expression builder syntax
correct, if indeed this is the correct way to do it!

I'd suggest using the IsDate() function in the Textbox's BeforeUpdate
event, which can be cancelled:

Private Sub txtDate_BeforeUpdate(Cancel as Integer)
If Not IsDate(Me!txtDate) Then
MsgBox "Invalid date.", vbOKOnly
Cancel = True
End If
End Sub

John W. Vinson[MVP]
 
G

Guest

Yes, I agree, but I don't know enough about MS Access at the moment to set up
things such as calendars.
 
G

Guest

You can download all the code needed from the internet. Just google 'Access
calendar'.
- Dorian
 

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