A form has an unbound TextBox field which has a Format property of Short Date. A user entered a value of 31/4/5 (i.e. incorrect - there is no 31st April) but Access accepted this input, with the result that value stored was 5/4/1931
How can I stop this behaviour so that 31/4/5 is errored as incorrect for that field, please?
Thanks
Silverback
Incorrect Date input not flagged
-
- Administrator
- Posts: 78535
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Incorrect Date input not flagged
Date input is processed by Windows - it tries to interpret the entry as best it can according to the user's system settings. Since 31 April is not a valid date, Windows assumes that the user intended 31 to be the year. You can't really prevent that.
Some possible ways to get "correct" dates:
Some possible ways to get "correct" dates:
- Use the Before Update event of the text box to check for "unlikely" dates - for example, if the date is supposed to be in this century, check whether the year is between 2000 and the current year.
- Use the Calendar control.
- Use separate text boxes for day, month and year, and perform your own validity checks.
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 777
- Joined: 29 Jan 2010, 13:30
Re: Incorrect Date input not flagged
Hans
Didn't expect that answer, but now I know, can sort our some sensible validation.
Thanks
Silverback
Didn't expect that answer, but now I know, can sort our some sensible validation.
Thanks
Silverback