Try to retrieve All records using an iif statement

jcaulfield

Board Regular
Joined
Nov 23, 2012
Messages
50
I am trying to run a query using criteria from a form. The criteria has a combo Box with 3 options All, Expense, or Income. With the following 2 formulas I get the correct results if I select "Income" or "Expense", but get nothing if select all.

IIf([forms].[sourcesSelect].[Cbx_IncExp]="All",<>"zzz",[forms].[sourcesSelect].[Cbx_IncExp])
IIf([Forms].[SourcesSelect].[Cbx_IncExp]="All",Is Not Null,[Forms].[SourcesSelect].[Cbx_IncExp])

<tbody>
</tbody>


If I eliminate the formula and enter <>"zzz" or "Is not Null", I get all records. Why doesn't my iif statement work? suggestion greatly appreciated.

Any help would be greatly appreciated.

Sincerely,

Stumped.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
If I eliminate the formula and enter <>"zzz" or "Is not Null", I get all records. Why doesn't my iif statement work? suggestion greatly appreciated.

Is all records what you want when you select all, because that sounds like what you want.
 
Upvote 0
You said you get correct results for Income and Expense records:
The criteria has a combo Box with 3 options All, Expense, or Income. With the following 2 formulas I get the correct results if I select "Income" or "Expense", but get nothing if select all.
I think you need to clarify or otherwise restate your problem more clearly.
 
Upvote 0
he wants a query to return all records

when he specifically states <> "zzz" or "Is not Null" as the criteria then he gets all records

but now he wants the query to get it criteria from a combobox

but he wants to keep "all" as an option in the combobox

so he made that formula

if the combobox choice = "all" then use the same criteria that worked for him before ---- <> "zzz" or "Is not Null" ----

but if the combobox choice does not = "all" then use the combobox choice as the criteria

but when he chooses "all" in the combobox no recorsds are returned

his question is "why does the criteria work when stated explicitly, but not when used in his formula"
 
Last edited:
Upvote 0
Hmm, I would still need to see the rest of it. Like how are either of these expressions actually being used? Are they part of a query? What is the query?
 
Upvote 0
Iif statements don't work like this in criteria of the Query when additional operators are added in - Not sure why, above my intelligence level.... but instead try this

In the Criteria put: [forms].[sourcesSelect].[Cbx_IncExp] Or [forms].[sourcesSelect].[Cbx_IncExp] = "All"

this way if you select any value in the combo the query will limit its results to what the combo box shows unless you select All in which case it shows all records.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,618
Messages
6,120,544
Members
448,970
Latest member
kennimack

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