Cannot get query criteria to work

Access 2010.

I have a form [Enquiries], with a combo box [cboSelectQualification]. The combo box selects a number which I want to use to limit the results of a query.
If there is no number selected i.e. the box is clean, then I want the query to return all values, but when a number is selected, the query must return only results corresponding to that number.
The criteria below works for the case where a number is selected, but results in no records shown if a value is not selected.

IIf(Len([Forms]![Enquiries]![cboSelectQualification])>0,[Forms]![Enquiries]![cboSelectQualification],Like "*" )

This below does also not return anything if nothing is selected.

IIf(Len([Forms]![Enquiries]![cboSelectQualification])>0,[Forms]![Enquiries]![cboSelectQualification],Like "*" & [Forms]![Enquiries]![cboSelectQualification])

Can you spot the problem please
Fritz PaulAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gustav BrockCIOCommented:
You can use this trick:

IIf(Len([Forms]![Enquiries]![cboSelectQualification])>0,[Forms]![Enquiries]![cboSelectQualification],[NameOfFieldYouAreFilteringOn])

/gustav
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fritz PaulAuthor Commented:
Thats awesome!

But was what I did wrong?
0
Gustav BrockCIOCommented:
Other methods may work but this trick is so simple.

/gustav
0
IrogSintaCommented:
In answer to your question, your LIKE operator should have been outside of your expression like so:
LIKE IIf(Len([Forms]![Enquiries]![cboSelectQualification])>0,[Forms]![Enquiries]![cboSelectQualification], "*" )

As Gustav said, there are a few ways to do this, here's how I normally do it:
LIKE NZ([Forms]![Enquiries]![cboSelectQualification], "*" )

Ron
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.