Re: Null values in date range, multiple criteria
- From: "Allen Browne" <AllenBrowne@xxxxxxxxxxxxxx>
- Date: Fri, 18 Aug 2006 01:47:19 +0800
Using:
<> "Closed"
won't handle nulls.
You would need:
WHERE (([Forms]![FrmSelect]![CmbStatus]="open")
OR ([Forms]![FrmSelect]![CmbStatus] Is Null)
OR (MyDate Between ...
And, yes, Access does make a mess of the SQL with combinations of AND and
OR. The bracketing is really crucial when you mix AND and OR. The query
design grid isn't really flexible enough, so it ends up repeating whole
tracts of it.
If you have several of these controls, and any could be Null, it might be
more efficient and flexible to leave the criteria out of the query, and
build a Filter string in code from only those boxes where the user entered
something. If that interests you, there's an example in this article:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Mark in Michigan" <MarkinMichigan@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message
news:B15BDADE-99BC-4376-B100-C60BF7745BC2@xxxxxxxxxxxxxxxx
Allen,
Thanks much - that worked! I just changed "=Open" to "<>Closed" to account
for null values in that control.
BTW, in design view, it added another row of criteria, duplicating all the
other fields and leaving "Closed Date" without criteria in the "or" row.
It
then added a column for the forms Status control, leaving that criteria
blank
in the first row and adding <>Closed as criteria in the "OR" row.
"Allen Browne" wrote:
Mark, switch the query to SQL View (View menu, in query design.)
Locate the WHERE clause.
Try something like this, replacing "MyDate" with the name of your date
field:
WHERE (([Forms]![FrmSelect]![CmbStatus]="open")
OR ([MyDate] Between [Forms]![FrmSelect]![TxtCloseDate]
And [Forms]![FrmSelect]![txtCloseDate2]))
By way of explanation, a WHERE clause ultimately evalutes to True (select
the record) or False (reject the record.) The clause above consists of 2
parts. With the OR operator, it evaluates to True if either part is true.
So, if the combo contains "open" the clause will evaluate to True for all
records. If the combo does not contain "open", the WHERE clause will be
true
only if the other part is true, i.e. if the date is between the 2 values.
"Mark in Michigan" <Mark in Michigan@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message
news:9378B2B2-8775-4C5F-83BC-4FFEFA4FCF39@xxxxxxxxxxxxxxxx
I'm trying to create a criteria to do the following:
If the "status" control on a form = "open", no criteria (want to pick
up
null values).
else:
pick up items within a date range as specified in two other controls.
I'm trying:
IIf([Forms]![FrmSelect]![CmbStatus]="open",Is
Null,<=[Forms]![FrmSelect]![TxtCloseDate] And
=[Forms]![FrmSelect]![txtCloseDate2])
to no avail. Any help much appreciated
.
- References:
- Re: Null values in date range, multiple criteria
- From: Allen Browne
- Re: Null values in date range, multiple criteria
- Prev by Date: Re: Updating from Many records to one table
- Next by Date: Re: Can I update a select query using an update query?
- Previous by thread: Re: Null values in date range, multiple criteria
- Next by thread: Re: conditions in the select clause?
- Index(es):
Relevant Pages
|