Restrict date

abby_1309

Registered User.
Local time
Today, 11:57
Joined
Mar 11, 2009
Messages
15
Hi ..I have a Date/Timew Field on my Form.How i can Restrict user to enter a Date Before or Equal to Today's date.
Thanks
 
in the beforeupdate event for the field

Code:
if nz(datefield,0)>date then
 msgbox("Date Cannot be after today")
 cancel = vbcancel 'refuses to accept it
 sendkeys "{esc}" 'undoes what he did, which is a nice interface idea
end if
 
in the beforeupdate event for the field

Code:
if nz(datefield,0)>date then
 msgbox("Date Cannot be after today")
 cancel = vbcancel 'refuses to accept it
 sendkeys "{esc}" 'undoes what he did, which is a nice interface idea
end if

I would avoid the use of SendKeys and you can just use the UNDO command -

Me.Undo

to undo the whole record or

Me.YourControlName.Undo

to undo the control value.
 
It works for Dates Greater then Today..but i want user to allow date equal or less then Today's date..what i have to change...
 
When i enter the Todays Date it Say's "Must Be Greater then Todays date"...
why is that?i need the date should be less or equal to todays' date
 
When i enter the Todays Date it Say's "Must Be Greater then Todays date"...
why is that?i need the date should be less or equal to todays' date

Can't really tell without seeing it.
 
the Date is coming from Data Base..which is set to be Date/Time and i want this function to be on updtae..could this be the case...?
 
the Date is coming from Data Base..which is set to be Date/Time and i want this function to be on updtae..could this be the case...?


What I meant was without seeing the database. What are the settings for that particular field in the table? When you say it "is coming from Data Base," do you mean a linked table from SQL Server or something? Or is it just in the current database?
 
its a Access data base...and field is set to be Date/Time in DB
 
When i enter the Todays Date it Say's "Must Be Greater then Todays date"...

i gave you a code snippet, but it didby have this text, and neither did anything else posted ot help you - so you must have got something from somewhere else that isnt working right. Can we see your code - you need the beforeupdate event for this date field
 
Remember, dates are defined as numerical codes in the system background, so you can use a numerical entry.

Select the field on the form design, then go to properties. In the data tab, Validation rule, enter <=date() for dates equal to or prior to today. Then you can add a Validation statement like "Entry must be today or before." - remember the quotes.

:)
 

Users who are viewing this thread

Back
Top Bottom