IIF function as query criteria (1 Viewer)

mikeTTI

Registered User.
Local time
Tomorrow, 08:52
Joined
Oct 7, 2007
Messages
41
I am trying to use an IIF function in each of three yes/no fields in a query to select records where one of the yes/no fields (as determined by a dialog form) = true, regardless of the value of the other two fields. Each record can contain any combination of Trues and Falses in these three fields.

The field to be evaluated will be determined based on a combo box on a dialog form. For example for the SALproc field the criteria cell contains: -

=IIf([Forms]![LevyReportDialog]![DialogCombo]="SAL","True","*")

There are corresponding functions in the criteria cell for the otehr two fields

So when I am reporting for SAL I can include all records where SALproc = true, regardless of whether the other fields are true or false.

I can get these functions to work in three separate text boxes on the dialog a form, and was feeling quite clever, but I can't get them to work as query criteria. I get an error message saying it is typed incorrectly or too complex.

I have also tried using the IIF functions in text boxes on the dialog form, and then using the value of those text boxes as criteria in the query. I get the same error message.

I can also get the query to select the records I want by manually entering True for the SALproc field and * for the other two yes/no fields, so the concept of using some combination of true, *, * as criteria appears to be valid.

I would really appreciate some help on this, I suspect I am not far away from making it work.

I'm assuming that it is actually possible to use an IIF function as a query criteria ... ...

In the meantime I am going to try creating functions containing the IIF functions and use those as criteria.
 
Last edited:

Jon K

Registered User.
Local time
Today, 21:52
Joined
May 22, 2002
Messages
2,209
The field to be evaluated will be determined based on a combo box on a dialog form. For example for the SALproc field the criteria cell contains: -

=IIf([Forms]![LevyReportDialog]![DialogCombo]="SAL","True","*")

There are corresponding functions in the criteria cell for the otehr two fields

So when I am reporting for SAL I can include all records where SALproc = true, regardless of whether the other fields are true or false.

See the attached database. It assumes the other two Yes/No fields are called ABCproc and XYZproc and the combo box contains the three options SAL, ABC and XYZ for user-selection.

Hope it's what you are after.
.
 

Attachments

  • Using IIF as selection criteria Access 2000.zip
    11.5 KB · Views: 5,541

mikeTTI

Registered User.
Local time
Tomorrow, 08:52
Joined
Oct 7, 2007
Messages
41
Thanks Jon K, that is very kind of you yo go to so much trouble.

That works perfectly.

Thanks

Mike
 

rohiiit

New member
Local time
Today, 16:52
Joined
Nov 20, 2007
Messages
4
IIF Function Problems

Hello guyz,

IIf(IsNull([JCR - Act Lab_Crosstab Hr]![CP]),0,[JCR - Act Lab_Crosstab Hr]![CP])

I am trying to use the following expression. Problem is [CP] exists sometimes, but sometimes not in [JCR - Act Lab_Crosstab Hr]. How can I put an If statement in this expression so that even if cp doesnt exsist, the querry will run?

Please help!!!

Ro
 

Rabbie

Super Moderator
Local time
Today, 21:52
Joined
Jul 10, 2007
Messages
5,906
Remember that the iif function always evaluates both the true and the false value everytime it is called. This means that you have to handle the case when [CP] does not exist. Read up on the NZ function. This may help you
 

rohiiit

New member
Local time
Today, 16:52
Joined
Nov 20, 2007
Messages
4
thanks Rabbie, I am not sure how to put Nz command in the followin expression? Can you help please?

IIf(IsNull([JCR - Act Lab_Crosstab Hr]![CP]),0,[JCR - Act Lab_Crosstab Hr]![CP]).
 

rohiiit

New member
Local time
Today, 16:52
Joined
Nov 20, 2007
Messages
4
i used this fucntion but access styll says tht CP doesnt exist

Nz([JCR - Act Lab_Crosstab Hr]![CP],0)
 

sadr110

New member
Local time
Today, 13:52
Joined
Jul 21, 2008
Messages
1
its true
like IIf([Forms]![LevyReportDialog]![DialogCombo]="SAL","True","*")
 

jordinho

New member
Local time
Today, 21:52
Joined
Jul 29, 2008
Messages
2
help

i need some help with IF statements in access. I have been asked to set up a query to calculate total duration in additional learning support.

the scenario is if the number of hours is less than 13 then that student is in band one. and if its greater than 13 its band two and so on. This is what my formula looks like so far:

=IIf([Total Duration]="13<","Band One","Band Two")

can you notify me of any problems why it may not be working

:D
 

Users who are viewing this thread

Top Bottom