QBF Multiple criteria And, Or, IIF?

emf

New member
Local time
Today, 03:31
Joined
Jan 25, 2014
Messages
3
Hello and thank you in advance,

I've never posted anything so I'm sorry if I etquette is incorrect.
I've got my table set (haha) as well as a query form, and a basic select query. I've got 8 fields in my select query and on my query form. When I set up the criteria as "And" I have to enter data in each of my query form fields or it won't work. When I set up the criteria as "Or" the query returns anything that matches any of the fields. I know, basic stuff, but this is where I'm stuck.
What I'm trying to do: I want the query to return results as it does when I use "And," but only for the query form fields I fill in.
I've tried IIF, IsNull, Nz but I'm no programmer so I might have screwed it up.
Here's what the first few query fields look like:

WHERE ((([CD LOG].CD_NO) Between [Forms]![CD LOG Query Form]![CD START #] And [Forms]![CD LOG Query Form]![CD END #]) AND (([CD LOG].DATE_ISSUED) Between [Forms]![CD LOG Query Form]![DATE ISSUED START] And [Forms]![CD LOG Query Form]![DATE ISSUE END]) AND (([CD LOG].VIOLATION)=[Forms]![CD LOG Query Form]![VIOLATION])

I'm going home and won't be back for a couple of days.
 
Last edited:
One way of doing it is to turn every = into a BETWEEN then use a NZ construct for each of the comparison values e.g. change

tbl1.f1 = frm1.textBox1

into

tbl1.f1 between nz(frm1.textBox1,0) and nz(frm1.textBox1,999999)


If it's a date field use 1 jan 1900 and 31 dec 2999 as the NZ alternatives

If it's a text field use CHR(0) and CHR(255)
 
I can try it until at least Friday, but i wanted to say thank you.
 
Thank you again Sensetech,
The Nz didn't work for me but you got me on the right path. I wound up useing a IIf exp with a IsNull exp. I had tried it before but I was useing "*" instead of dates & numbers. It works great now. This is what it looks like:
WHERE ((([CD LOG].CD_NO) Between IIf(IsNull([Forms]![CD LOG Query Form]![CD START #]),"2013-047-001",[Forms]![CD LOG Query Form]![CD START #]) And IIf(IsNull([Forms]![CD LOG Query Form]![CD END #]),"9999-047-999",[Forms]![CD LOG Query Form]![CD END #])) AND (([CD LOG].DATE_ISSUED) Between IIf(IsNull([Forms]![CD LOG Query Form]![DATE ISSUED START]),#1/1/2010#,[Forms]![CD LOG Query Form]![DATE ISSUED START]) And IIf(IsNull([Forms]![CD LOG Query Form]![DATE ISSUE END]),Date(),[Forms]![CD LOG Query Form]![DATE ISSUE END])) AND (([CD LOG].VIOLATION) Like IIf(IsNull([Forms]![CD LOG Query Form]![VIOLATION]),"*",[Forms]![CD LOG Query Form]![VIOLATION]))
 

Users who are viewing this thread

Back
Top Bottom