Query Date Criteria

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,347
Office Version
  1. 365
Platform
  1. Windows
Can you use an IIF statement in the query?

I want to be able to say

if a Check Box = Yes than show all,
If the Start and End Text Box where the criteria is looking for the date range are null = then show all
If the Start TextBox where the criteria is null show all that are earlier than whats in the End Textbox up to the ate in the End Textbox
If the Start Date is not null and the End Date is null (or blank) the show all from the start date and later.

Yes that's a mouth full!

Thanks
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
This is my attempt, using a query and a form with two unbound text boxes:
PHP:
SELECT *
FROM GlucoseReadings
WHERE (((GlucoseReadings.[RecordDate])>=DateValue(Nz([Forms]![Form1].[txtStartDate].[Value],"1/1/1970")) And (GlucoseReadings.[RecordDate])<=DateValue(Nz([Forms]![Form1].[txtEndDate].[Value],"12/31/2099"))));

Using the date value function because the values in the textboxes are text, not values with date datatypes (and ignoring the danger of invalid entries in a freeform text box, for now).

Basically, if the dates are missing/null/blank/empty then we are just substituting a minimum date that represents the beginning of time for some relevant period, and likewise for the maximum date.
 
Upvote 0

Forum statistics

Threads
1,221,692
Messages
6,161,327
Members
451,697
Latest member
pedroDH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top