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 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.
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.