Solved

Access Like "*" in IIf Statement of Criteria Returns No Records

Posted on 2010-08-25
7
475 Views
Last Modified: 2013-11-29
Hi Experts,

I am developing an Access db with two tables for Regions and Provinces. The tables are called tbl_Regions and tbl_Province respectively. They are joined one-to-many where each region has many provinces. I have a Main form with two combo boxes cmb_Region and cmb_Province. I want to use each box in the criteria of a query. The bound value for each is an integer (AutoNumber) value. When a user selects a region, the query should return the records for that region and all provinces. If the user also selects a province, only that provinces records should be returned.

I have the following criteria for the Region ID (rID) and it works fine:

[Forms]![frm_Main]![cmb_Region]

I have the following in the criteria for the Province ID (pID) and it does not return any records:

IIf([Forms]![frm_Main]![cmb_Province]="", Like "*",[Forms]![frm_Main]![cmb_Province])

If I just put Like “*” in the criteria I get all Provinces. If I enter a literal (like the number 4) instead of Like “*” for the true side of the IIf, I get the Province 4 records. The IIf statement seems to working correctly. It is just when I try to use Like”*” within it that I have a problem.

LikeInIIf.doc
0
Comment
Question by:KevinS2112
  • 3
  • 2
  • 2
7 Comments
 
LVL 6

Expert Comment

by:Patrick Tallarico
ID: 33525119
IIf([Forms]![frm_Main]![cmb_Province]="", "*",[Forms]![frm_Main]![cmb_Province])

What happens if you try it without the like?
0
 

Author Comment

by:KevinS2112
ID: 33525177
It gives the "too complex of incorrectly typed error"
0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 250 total points
ID: 33525501
You have a syntax error,
Also, to use  IIF correctly you should specify what to do when the result is true and when the result is False,

Try:

IIf([Forms]![frm_Main]![cmb_Province]="", Like "*" & [Forms]![frm_Main]![cmb_Province] ,"cmb_Province has a specific value")

I am sure you can adapt this to work in your database.

If not, then can you take a step back and explain to us what your ultimate goal is here, ...there may be a more efficient way to do this...

For eaxmple: If your goal is to show all records if no value is selected, the this is typically done simply like this in the query criteria for "ProvinceID:
    Like "*" & [Forms]![frm_Main]![cmb_Province] & "*"

(No real need for IIF...)



;-)

JeffCoachman
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 6

Expert Comment

by:Patrick Tallarico
ID: 33525708
IIf([Forms]![frm_Main]![cmb_Province]="", "",[Forms]![frm_Main]![cmb_Province])

Perhaps you could try an empty string as the first option in the IIF statement since you will not actually need criteria for that field.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 33525906
Sample attached:

Database19.mdb
0
 

Author Comment

by:KevinS2112
ID: 33526131
Thanks, boaq200! The second option you mentioned without IIf did the trick.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 33526400
;-)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now