By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,790 Members | 1,398 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,790 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?

Thanks

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


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

Regards,
Fish.
Jan 15 '09 #2

MindBender77
100+
P: 234
@tbeers
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.

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

-Thanks

-Tom
Jan 15 '09 #4

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

Format([text0],"yy")=Format(Date(),"yy")
Jan 15 '09 #5

MindBender77
100+
P: 234
@tbeers
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
  8.  
Note, this is untested.

HTH,
Bender
Jan 15 '09 #6

Post your reply

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