View Full Version : A query that shows records from now until the end of the month...


insixt
12-21-2009, 06:15 AM
I'm doing a database that records jobs to be completed.

I want to be able to see what jobs are due for this month, what jobs are due next month and what jobs are due two months from now (seperate query for each of these). I need it to work forever and thus can't use set dates.

How would I go about doing this, I know I should use 'now' somewhere in the filter term but I don't know the rest!

Please help!
http://www.accessforums.net/images/misc/progress.gif

JPaulo
12-21-2009, 06:21 AM
In an empty column of your query:

MonthRef: Format([YourFieldDate];"mm")

In criteria:
Format(Date();"mm")

Or
Format(Date();"mm")+1

Or
Format(Date();"mm")+2

insixt
12-21-2009, 06:29 AM
edit - Cheers for your help!

insixt
12-21-2009, 07:11 AM
Hi - just tried this and I'm getting an error message

"The expression you entered contains invalid syntax."

Any help on this?

boblarson
12-21-2009, 07:18 AM
Hi - just tried this and I'm getting an error message

"The expression you entered contains invalid syntax."

Any help on this?

You probably need to replace the semi-colon (;) with a comma (,) because of your regional settings.

insixt
12-21-2009, 07:24 AM
Thanks boblarson! However, unfortunately now I'm getting this message.

'Data type mismatch in criteria expression.'

Any ideas?

raskew
12-21-2009, 07:36 AM
Hi -

try Between Date() and DateSerial(year(date()), month(date()) + 1, 0) in your date field's criteria.

HTH - Bob

boblarson
12-21-2009, 07:37 AM
However, that is not likely going to work because when you get to November it would fail (Month 11 + 2 = 13 and there is no month 13).

So, you would need:

On your Date Field Criteria (no new field needed):

Current Month:

Between Date() and DateSerial(Year(Date()), Month(Date())+1, 0)


Next Month:

Between DateSerial(Year(DateAdd("m",1,Date())),Month(DateAdd("m",1,Date())),1) And DateSerial(Year(DateAdd("m",1,Date())),Month(DateAdd("m",1,Date()))+1,0)

Next 2 Months:
Between DateSerial(Year(DateAdd("m",2,Date())),Month(DateAdd("m",2,Date())),1) And DateSerial(Year(DateAdd("m",2,Date())),Month(DateAdd("m",2,Date()))+1,0)

boblarson
12-21-2009, 07:39 AM
Hi -

try Between Date() and DateSerial(year(date()), month(date()) + 1, 0) in your date field's criteria.

HTH - Bob

Darn, knew someone was going to do that while I was working out all of the others :D

insixt
12-21-2009, 07:47 AM
Boblarson, Thank you so much! You've made my day with your help! Thanks to everybody else aswell :D.

insixt
12-23-2009, 02:17 AM
Arrrggh - Sorry guys I thought this was solved but I didn't test it properly. The one for First Month that boblarson posted works fine. But with the other two I keep getting the message:

'The expression you entered contains invalid syntax - You may have entered an opeand without an operator.'

Any suggestions on how to fix this?

JPaulo
12-23-2009, 02:27 AM
hi man, remove the space:

Next Month:

Between DateSerial(Year(DateAdd("m",1,Date())),Month(DateA dd("m",1,Date())),1) And DateSerial(Year(DateAdd("m",1,Date())),Month(DateA dd("m",1,Date()))+1,0)

Next 2 Months:
Between DateSerial(Year(DateAdd("m",2,Date())),Month(DateA dd("m",2,Date())),1) And DateSerial(Year(DateAdd("m",2,Date())),Month(DateA dd("m",2,Date()))+1,0)

Correct:


Next Month:

Between DateSerial(Year(DateAdd("m",1,Date())),Month(DateAdd("m",1,Date())),1) And DateSerial(Year(DateAdd("m",1,Date())),Month(DateAdd("m",1,Date()))+1,0)

Next 2 Months:
Between DateSerial(Year(DateAdd("m",2,Date())),Month(DateAdd("m",2,Date())),1) And DateSerial(Year(DateAdd("m",2,Date())),Month(DateAdd("m",2,Date()))+1,0)

insixt
12-23-2009, 02:38 AM
That fixed it. Thanks so much!

boblarson
12-23-2009, 08:33 AM
That fixed it. Thanks so much!

Yeah, I should have surrounded the code with code tags because the site here adds a space after about 80 characters. It is a bit of a strange bug that is known here.