No 31st of January!?

XelaIrodavlas

Registered User.
Local time
Today, 19:22
Joined
Oct 26, 2012
Messages
175
I had to double check too... for some reason my form wont pick up the 31st of any month in my input form (jan, mar, may, july, aug, oct, dec).

I have a simple search form (no control source) that runs a query which is based on the records between two input dates (text boxes). These could be any days, but could also be by month, so for the users convenience I wanted an option to just choose a month and year, which would automatically fill out the input boxes.

Maybe there's an easy way to do this? This is how I tried...

The start date box was easy, i just set the control source to:

="01/" & [Month] & "/" & [Year]

which produces normal dates like 01/02/2013 or 01/11/2010.

But because the months have different number of days, the ending date was a bit more complex, I used iif statements in the control source and have this:

=IIf([Month]="02" And [Year]/4=Int([Year]/4),"29/" & [Month] & "/" & [Year],
IIf([Month]="02","28/" & [Month] & "/" & [Year],
IIf([Month]="04" Or "06" Or "09" Or "11","30/" & [Month] & "/" & [Year],
IIf([Month]="01" Or "03" Or "05" Or "07" Or "08" Or "10" Or "12","31/" & [Month] & "/" & [Year],"FALSE"))))

The "01" bits refer to the bound column reference in each month, february is 02, december is 12 etc.
This successfully sets the date to the 28th if February (29th on leap years, see first line), and the 30th for Apr, June, Sep and Nov. But for some reason the last IIf statement doesn't work right, it just keeps setting it to the 30th, and i can't change it manually.. so if i run the query it then works only until the 30th of these months even when there's 31 days.

Have I made a really simple mistake and just can't see it? it should be working... but it isn't...

Any ideas? Thanks
 
thinking on it, could the problem be the 'Or' in my function? that looks to be where I'm getting stuck... is there a better way to say if x = Y Or Z other than just writing each IIf individually?

Good brainstorming :D
 
Hello Alex, I am sure that what you are trying to do could be easily achieved in a simple VBA function, but I am finding it a bit hard to understand..

Do you wish to just get the Last date of a month, for any given date? If so this might be what you are looking for..
Code:
? DateSerial(Year(Date),Month(Date)+1,0)
28/02/2013 
? DateSerial(Year(#15/06/2013#),Month(#15/06/2013#)+1,0)
30/06/2013
 

Users who are viewing this thread

Back
Top Bottom