Date cannot be after today

Rusty

Registered User.
Local time
Today, 05:36
Joined
Apr 15, 2004
Messages
207
Hello,

I have a date field on a form and I don't want the user to be able to enter a date that's in the future, i.e. not after today. I have tried using the code below and want the field to be blanked out and a message box to appear telling them that they can't do that.

Is it something like the code below plus:

DateOfEvent.Undo
MsgBox "You CANNOT enter a date which is AFTER today"

Please help,

Rusty
:confused:

Code:
Private Sub DateOfEvent_AfterUpdate()

If (Me.DateOfEvent > Date) Then
 
Try this

Instead of code use the validation rule for the field.

Bring up the properties form for the field and in validation rule put <= date()
ie today or before

and in validation text put your message e.g please enter a date thats not in the future.

I tried it and it gave the message and took me back to the field to try again.

Sue
 
I already have a validation rule for this field specified in the table as "Is Not Null".

I need code for the other date event to specify <=Date()

Rusty
:(
 
try combining the two validation rules ie:

<=Date() And "is not null"

is just tried this and it asked for a date before today if i entered a future date, or if I deleted the date altogether and tried to leave the field.
Obviously you need to word the message carefully to accomodate both versions.

Sue
 

Users who are viewing this thread

Back
Top Bottom