473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

DateTimePicker changing max date parameter

108 100+
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
9 4479
PEB
1,418 Expert 1GB
Hi
U can use

DateSerial(year(Now())+2, DatePart("m", Now()), Day(Now()))
Nov 25 '06 #2
robtyketto
108 100+
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
14,534 Expert Mod 8TB
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
robtyketto
108 100+
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
1,418 Expert 1GB
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
robtyketto
108 100+
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
1,418 Expert 1GB
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
robtyketto
108 100+
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
robtyketto
108 100+
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

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

Similar topics

0
by: Bhavna | last post by:
I have a datetimepicker (dtp) on my windows form the user initially selects a date and then selects the rooms they wish to book The problem i have is that when the user goes back and tries to...
9
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it...
9
by: Ed Crowley | last post by:
I have a DateTimePicker control on my form that is displaying the date format in UK format (dd/mm/yy). However, in my code dtpStartDate.Value gives a date in US format, but...
0
by: ROG | last post by:
Hi all with help from postings on the web, i have a dateTimePicker in one of my columns in the datagrid. However, when i move in to this column using the arrow keys, it automatically pops up,...
0
by: Steve Cutting | last post by:
Hi all, I have created a form used for entry of repair details into a table on a MSDE database. I am using a datetimepicker for entry of the repair date. It is set to SHORT display format and I...
7
by: Clamara | last post by:
When adding a new record from my form, I pre-set my DateTimePicker's value to System.DateTime.Today Since the "Today" value is used most of the time, the user doesn't need to select a date from...
3
by: Charlie | last post by:
In the top portion of the DateTimePicker, where the value of the date is displayed, how can I detect whether the month or day or year is currently focused, or, if ShowCheckBox = True, whether the...
1
by: Kevin | last post by:
I have put a VS2005 sample project up here: http://www.kevinandkiran.com/CSharpApplication.zip (its only 50k) Basically I have a class that contains a date property, which is initialised to...
5
by: Mike | last post by:
Hi, I use MS SQL Express and VS 2005 c#, win application. I would like to select value rom DateTimePicker and list all values for selected date within GridView. I have method as follows: ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.