Date Input

kitty77

Registered User.
Local time
Yesterday, 23:31
Joined
May 27, 2019
Messages
719
I have a date field with a date picker on a form. How can I prevent the user from inputting the wrong year? Basically if the data entry is this year then use 2020.
I want to prevent an incorrect year.
 
The best place to validate data entry is in the BeforeUpdate event. In this case, you might try using the Control's BeforeUpdate event.
 
The date field with a date picker on a form has events such as control_CHANGE and control_LOSTFOCUS. In either of those events, you could perform a simple check as to whether a date was picked and, if so, was valid. You can look at the DatePart function which can give you a four-digit year as one of its returns.


The above is the quick&dirty reference for same.

Basically, if you have a date in the control in the CHANGE or LOSTFOCUS event then you could compare to the year for the current date.

Code:
IF ( Datepart("yyyy", control-name ) <> Datepart("yyyy", Date() ) ) AND ( NZ(control-name),"") <> "" ) THEN
    complain and do something about it
END IF

I didn't write more than that because you didn't suggest what you really wanted to do and you also have choices about when you would use this. But this is the basics of it.
 
Be aware of situations at the beginning and end of a year. For example, a situation where data is being entered on January 2 for the previous year.
 

Users who are viewing this thread

Back
Top Bottom