Date check in VBA

PaquettePaul

Member
Local time
Today, 03:23
Joined
Mar 28, 2022
Messages
107
Quick quesrrion regarding date validation. i looked for an answer but found zilch.

User enters a date and in the Before Update process in the form, I check to see if the specified date is greater than the current date or more than a year in the past. Also want to store the results from the date picker in date only format. Solution would be great.
 
Not sure I understand what you're asking. What have you tried? What happened? Is it an unbound Textbox?
 
First, dates are not stored as dates anyway. They are stored as a typecast, or you might call it an alternate interpretation, of type DOUBLE. When dealing with dates, you hardly EVER store them as anything other than the DATE data type. The key is not the data type, but the default data format.

The "BeforeUpdate" event includes a Cancel option, so you can pass back a value of -1 (as TRUE) or 0 (as FALSE) to tell Access whether you want to cancel the update.


EDIT: Added link to event description.

Checking dates is easy. You want to find if the date is future?

IF Date() < CDate( Me.UserDate) THEN .... and do whatever you wanted to do for future dates.

Then, you want more than a year in the past?

IF ( Date() - CDate( Me.UserDate ) ) > 365 THEN ... and do whatever you wanted for dates more than a year old.
 
Quick quesrrion regarding date validation. i looked for an answer but found zilch.

User enters a date and in the Before Update process in the form, I check to see if the specified date is greater than the current date or more than a year in the past. Also want to store the results from the date picker in date only format. Solution would be great.
Here you go.
 

Users who are viewing this thread

Back
Top Bottom