M. Ö.
M. Ö.

Reputation: 71

Microsoft Access if statement with two possible filter

I want to filter according to selection but what I'm trying to do is that if Q1 and Q2 option selected I want to filter them for both Q1 and Q2. Here is code I wrote and not working:

Like IIf([Forms]![Form1]![Combo1]="All";"Q1" Or "Q2";[Forms]![Form1]![Combo1])

After running this code, program changes "Q1" Or "Q2" part to ([QQuery].[Q])="Q1" Or ([Q_Query].[Q])="Q2".

I'm already able to filter one by one, I mean for Q1, for Q2 or for Q3 seperately. How can I filter, for Q1 and Q2 at the same time. Thanks.

Upvotes: 0

Views: 1548

Answers (2)

M. Ö.
M. Ö.

Reputation: 71

OK, I finally did it! This what I wrote:

IIf([Forms]![Form1]![Combo1]="Q1+Q2";"Q1"; [Forms]![Form1]![Combo1]) Or IIf([Forms]![Form1]![Combo1]="Q1+Q2";"Q2";[Forms]![Form1]![Combo1]) 

and so on. but if you want to add All part, you have to add to the end of codes above:

Or Like IIf([Forms]![Form1]![Combo1]="All";"*";[Forms]![Form1]![Combo1]) 

Hope this helps other people having same problem Thanks again Linger :)

Upvotes: 1

Linger
Linger

Reputation: 15068

You are not specifying a wild card so you are not actually using LIKE and the result would be the same as if you used equality operator (=).

I do believe the below will work better for you. Replace Quarter with the actual field name. I put them in parentheses just in case you have any other criteria you are adding to the WHERE clause.

IIf([Forms]![Form1]![Combo1]="All"; "(Quarter = 'Q1' Or Quarter = 'Q2')";[Forms]![Form1]![Combo1])

If you truly need to use LIKE then it should look something like the following:

IIf([Forms]![Form1]![Combo1]="All";"(Quarter LIKE '*Q1*' Or Quarter LIKE '*Q2*')";[Forms]![Form1]![Combo1])

Upvotes: 0

Related Questions