By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,131 Members | 1,312 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,131 IT Pros & Developers. It's quick & easy.

Force Current Year

P: 64
Good morning.

I am running a timecard program in Access 2007 and it seems that the users have trouble entering the correct year when entering the date in the date field. Date field entry format is mm/dd/yy and is displayed as mm/dd/yyyy.

How can I force the current year to be entered?


Jan 15 '09 #1
Share this Question
Share on Google+
5 Replies

Expert 2.5K+
P: 2,653
Hello, Tom.

Try to reconstruct date entered by user with DateSerial() function.
Day() and Month() functions will help you to extract correspondent values from user input while Year(Date()) will give you current year.

Jan 15 '09 #2

P: 234
My first question is what type of control is the date field in ie. Textbox?

Second, why do you need to have them enter this manually. You could simply have the control source of the textbox =Date(). Which will produce the current date automatically.

Jan 15 '09 #3

P: 64
I have the textbox = date() set, but sometimes they enter time for different days other than the current day. I just want an alert or procedure that keeps any year other than current year from being entered.


Jan 15 '09 #4

Expert 100+
P: 1,287
In the text box's validation rule put:

Jan 15 '09 #5

P: 234
You could set the enable property of the textbox to "false" which should prevent users from changing anything you don't want them to change. It will just gray out the textbox but, retain the data.

Or something like this in OnExit event of your textbox:
Expand|Select|Wrap|Line Numbers
  1. If format(" & Textbox1 & ", "yy")  <> format(Date,"yy") Then
  2. msgbox("Please Enter the Current year.")
  3. docmd.cancelevent
  4. textbox1.setfocus
  5. else
  6. 'do something here.........
  7. end if
Note, this is untested.

Jan 15 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.