Query Criteria to give a date range (1 Viewer)

MaxTorque

Registered User.
Local time
Today, 01:25
Joined
Dec 14, 2016
Messages
13
Hi Guys,

This is probably a simple syntax issue for me but I am struggling to find an answer.
I am querying a table which contains 3000+ records which include a date field with an expiry date.
I would like an expression to filter expired dates including Null values and all records with an expiry date due up to and including the end of the following month.

I have had some success using the following:
Code:
Between DateAdd("m",-24,Date()) And DateAdd("d",39,Date()) Or Is Null
The problem is I have to keep manually changing the value in the
Code:
DateAdd("d",39,Date()
section (39 in the example) in order to get the number of days from today up to the end of the following month. I have tried using
Code:
DateAdd("m",+1,Date()
but it does not include all records up to the end of the month.
Is there an expression that will give me all records up to the end of the following month automatically regardless of when I run the query?

Any help gratefully received
 

Tieval

Still Clueless
Local time
Today, 01:25
Joined
Jun 26, 2015
Messages
475
DateSerial should give you the end of a specific month.
 

stopher

AWF VIP
Local time
Today, 01:25
Joined
Feb 1, 2006
Messages
2,395
Like Tieval says, you can use DateSerial. The tricky bit is determining the last day of the month.

Take a look at this:

Code:
DateSerial(Year(DateAdd("m",2,date())),Month(DateAdd("m",2,date())),0)

The idea here is you add two months to the current date to determine the year and month after the one you want. Then use these along with a value of zero for day in the DateSerial function. Using zero (0) as the day value gives you the date for the last day of the previous month (which is the last day of the month we want).

hth
 

MaxTorque

Registered User.
Local time
Today, 01:25
Joined
Dec 14, 2016
Messages
13
Like Tieval says, you can use DateSerial. The tricky bit is determining the last day of the month.

Take a look at this:

Code:
DateSerial(Year(DateAdd("m",2,date())),Month(DateAdd("m",2,date())),0)

The idea here is you add two months to the current date to determine the year and month after the one you want. Then use these along with a value of zero for day in the DateSerial function. Using zero (0) as the day value gives you the date for the last day of the previous month (which is the last day of the month we want).

hth
Hi stopher,
Thank you so much for your excellent explanation, this returns the values I was looking for.
No wonder I was struggling, I would not have come up with that. I wish I could think like a programmer but I find it hard as a newbie to access to think laterally in order to solve issues like this.

Thanks also to Tieval for pointing me in the right direction
 

Users who are viewing this thread

Top Bottom