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

DateTimePicker changing max date parameter

100+
P: 108
Is there anyway to change the max date to

datenow + 2 years

I tried this in the properties -> Format -> MaxDate = dateadd("yyyy",2,date())
without success :(

Can anyone help.

Thanks, a big thank you to all those who've helped me previously too :)
Nov 25 '06 #1
Share this Question
Share on Google+
9 Replies


PEB
Expert 100+
P: 1,418
PEB
Hi
U can use

DateSerial(year(Now())+2, DatePart("m", Now()), Day(Now()))
Nov 25 '06 #2

100+
P: 108
HI,

Thanks for the reply.

I think the problem is that I need VBA code to allow me to change the parameter of the DateTimepicker as you cant enter argumetns directly into the property maxdate :( then attach it to an event on the form load.

No idea how to go about it though.
Nov 25 '06 #3

MMcCarthy
Expert Mod 10K+
P: 14,534
HI,

Thanks for the reply.

I think the problem is that I need VBA code to allow me to change the parameter of the DateTimepicker as you cant enter argumetns directly into the property maxdate :( then attach it to an event on the form load.

No idea how to go about it though.
You are trying to put something into format that is actually a validation rule.
Nov 25 '06 #4

100+
P: 108
You are trying to put something into format that is actually a validation rule.
Thanks, I was thinking that from the error message.

Can I set a limit then using VBA code?
Its an activex control my knowledge about these and VBA you could put on a postage stamp!
Nov 25 '06 #5

PEB
Expert 100+
P: 1,418
PEB
So u can put this vba code in BeforeUpdate Event in the respective Date Field:

Expand|Select|Wrap|Line Numbers
  1. IF me![MyDate].Value>DateSerial(year(Now())+2, DatePart("m", Now()), Day(Now())) then
  2. Msgbox "Your date should be less than " +str(DateSerial(year(Now())+2, DatePart("m", Now()), Day(Now())))
  3. Update=False
  4. end if
  5.  
Nov 25 '06 #6

100+
P: 108
Much appreciated , the msgbox appears but what the command to set the focus again in the date field (dtpicker9) as at the moment you can click on another field.

Thanks :)
Nov 25 '06 #7

PEB
Expert 100+
P: 1,418
PEB
In fact the solution can be

IF me![dtpicker9].Value>DateSerial(year(Now())+2, DatePart("m", Now()), Day(Now())) then
Msgbox "Your date should be less than " +str(DateSerial(year(Now())+2, DatePart("m", Now()), Day(Now())))
Updated=False
Me!dtpicker9.Undo
Me!dtpicker9.Setfocus
end if
Nov 25 '06 #8

100+
P: 108
In fact the solution can be

IF me![dtpicker9].Value>DateSerial(year(Now())+2, DatePart("m", Now()), Day(Now())) then
Msgbox "Your date should be less than " +str(DateSerial(year(Now())+2, DatePart("m", Now()), Day(Now())))
Updated=False
Me!dtpicker9.Undo
Me!dtpicker9.Setfocus
end if
I cant understand why as It end the IF condition and displays the message box but it doesnt leave the focus on the dtpicker. Doesnt complain about it but doesnt set focus.

Also had to remove the Undo as isnt an option with the version of access I have.
Nov 26 '06 #9

100+
P: 108
I should have re-read that before posting!

What I wanted to say is the message box appears but setfocus doesnt appear to function for datetimepicker.

Doesnt complain about syntax or error either.
The undo however is a recognised command so had to remove it.

Thanks for your help :)
Nov 26 '06 #10

Post your reply

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