set a criteria for 2 txt fields in my form (1 Viewer)

mattaus

Registered User.
Local time
Yesterday, 19:19
Joined
Apr 27, 2009
Messages
35
Hi,

ive got to txt fields fin my form called "txtStartDate" and "txtEndDate" where the user enters the start date and end date as a criteria o the report..howver i want to limit the date range to a 12month period for example the following date range would work:

between
01/04/2008 and 31/03/2009

however the following would not work..

01/04/2008 and 31/04/2009

01/04/2008 and 28/02/2009
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 12:19
Joined
Jan 20, 2009
Messages
12,863
Easiest way is to set the validation rule properties

txtStartDate Validation Rule: >txtEndDate-365
txtEndDate Validation Rule: <txtStartDate+366

Set the EndDate default to some value otherwise you won't be able to enter the start date.

Date() which means today.
Or
DMax("datefield", "yourtable") which is the newest date in your data

If beyond this date Access complains rather in a rather inelegant message when you try to leave the field.

---------------
Using this VBA statement in the AfterUpdate event procedure will automatically reduce the range to 365 days:
If txtEndDate>txtStartDate+365 Then: txtEndDate = txtEndDate+365

Somethng complementary in the Start field event will do the same if the end date is entered first. Enter some default in the End table.

If you want to deal with leap years you can parse the date using some of the date functions. Year(txtEndDate), Month(), etc
 

mattaus

Registered User.
Local time
Yesterday, 19:19
Joined
Apr 27, 2009
Messages
35
Thanks for this and v.sorry for the late reply
 

Users who are viewing this thread

Top Bottom