Extracting Next months data based on a date field

Hello experts,
I have a table holding a date field (Maintenance visits due).
I need to be able to run a report at any time in the current month that shows visits due next month.
So in December i need to see records for Jan etc etc.
My date field is "NextMaint" and I can a query that gives me the month for that 'Month: Format([nextmaint],"mm")' and the current month 'Currentdate: Format(Now(),"mm")'
However, I am a bit lost from there. Any help greatly appreciated.
iainmacleodAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pawan KumarDatabase ExpertCommented:
You can use DateADD to get the next month.

DateAdd("mm", 1, NextMaint)

Try like this..

Format(DateAdd("mm", 1, NextMaint),"mm")'
0
Bill PrewCommented:
You can select all records for next month with a query like below.  This selects all dates greater or equal to the first day of the next month, and less or equal to the last day.

SELECT *
FROM tblTest
WHERE (((tblTest.NextMaint)>=DateSerial(Year(DateAdd("m",1,Now())),Month(DateAdd("m",1,Now())),1)
AND (tblTest.NextMaint)<=DateSerial(Year(DateAdd("m",2,Now())),Month(DateAdd("m",2,Now())),1)-1));

Open in new window

0
Bill PrewCommented:
You can also do the following, although depending on data size and if the date field is indexed the prior may perform better.  But this one reads simpler :-).

SELECT *
FROM tblTest
WHERE Year(tblTest.NextMaint) = Year(DateAdd("m",1,Now())) 
AND Month(tblTest.NextMaint) = Month(DateAdd("m",1,Now()));

Open in new window


»bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Bill PrewCommented:
And probably a little safer for the boundary days in case they have time components...

SELECT *
FROM tblTest
WHERE tblTest.tstDate>=DateSerial(Year(DateAdd("m",1,Now)),Month(DateAdd("m",1,Now)),1) 
AND tblTest.tstDate<DateSerial(Year(DateAdd("m",2,Now)),Month(DateAdd("m",2,Now)),1);

Open in new window


»bp
0
Pawan KumarDatabase ExpertCommented:
You can use like below -
DATEVALUE.

SELECT * FROM yourtableName
WHERE NextMaint BETWEEN DATEVALUE(Now()) AND DATEVALUE(DATEADD( "m",1, Now()))

Open in new window

0
iainmacleodAuthor Commented:
Thank you both very much.
I went with Bills solution in the end, but great to have the knowledge of both.
What a great resource this site is...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.