Query criteria from a Form

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,347
Office Version
  1. 365
Platform
  1. Windows
I have a query where I use the value from a Combo box on a form as the criteria
Forms]![frmEstimates]![ComboPidSelected]

This woked fine. But I need to adjust it so that when nothing is selected in the Combo Box that the query puled Everything. So I tried an Iff formula

IIf(IsNull([Forms]![frmEstimates]![ComboPidSelected]),"*",[Forms]![frmEstimates]![ComboPidSelected])

Is my formula wrong or maybe this is something you cannot do.

I get an error message: "This Calculated column contains an invalid expression"

Pre IIf statement it worked fine.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Are you using LIKE in this query? It's not clear how the expression is being used. You should also be debugging the result of the expression:
Code:
msgbox IsNull([Forms]![frmEstimates]![ComboPidSelected]),"*",[Forms]![frmEstimates]![ComboPidSelected])
I would test this way with a null value, an empty string, and an actual value.
 
Upvote 0
This is in the query under the Criteria section - not in VBA

I don't understand the msgbox portion of what you suggest.
 
Last edited:
Upvote 0
You can use the msgbox on your form.
Add a button, and have it display the value of the expression.
The same can be done in the immediate window or in other ways - you don't need to use a msgbox, you just need to be able to debug by seeing the evaluated result of the expression.

If you are using this in a query you need a name for the column with the expression.
MyColumnName: <expression>

Did you confirm you are using LIKE ?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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