Date Criteria Question

  • Thread starter Thread starter Joe Williams
  • Start date Start date
J

Joe Williams

I use a lot of queries that resrtict records by looking at the beginning and
ending dates of a form to do a BETWEEN DATE1 and DATE2 statement in the
query.

My question is how do I construct a query such that if the user leaves the
date fields blank it will return all records, but if they fill them in then
it will only give the records for that date range?

As I have it right now (between statement seen above) if the users leaves
the date fields blank then you will get zero records returned.

Thanks

joe
 
Dear Joe:

I suggest you should move away from using the BETWEEN, and use it's
equivalent. This step would look like:

SomeDate >= DATE1 AND <= DATE2

This won't fix it. It yields the same result. But on this we can
readily build what you want:

(SomeDate >= DATE1 OR DATE1 IS NULL) AND (SomeDate <= DATE2 OR DATE2
IS NULL)

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts
 
Tom, works great! thanks for the help

- joe


Tom Ellison said:
Dear Joe:

I suggest you should move away from using the BETWEEN, and use it's
equivalent. This step would look like:

SomeDate >= DATE1 AND <= DATE2

This won't fix it. It yields the same result. But on this we can
readily build what you want:

(SomeDate >= DATE1 OR DATE1 IS NULL) AND (SomeDate <= DATE2 OR DATE2
IS NULL)

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Access Dcount (multiple criteria) 3
If/Then/Else Query 6
Date Range Query 6
#error - Blank 3
query to pull between two dates 4
Problem with Date Query 6
Using Between...And with General Date 2
IIF question 3

Back
Top