Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 506
  • Last Modified:

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

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
KevinS2112
Asked:
KevinS2112
  • 3
  • 2
  • 2
1 Solution
 
Patrick TallaricoCommented:
IIf([Forms]![frm_Main]![cmb_Province]="", "*",[Forms]![frm_Main]![cmb_Province])

What happens if you try it without the like?
0
 
KevinS2112Author Commented:
It gives the "too complex of incorrectly typed error"
0
 
Jeffrey CoachmanCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Patrick TallaricoCommented:
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
 
Jeffrey CoachmanCommented:
Sample attached:

Database19.mdb
0
 
KevinS2112Author Commented:
Thanks, boaq200! The second option you mentioned without IIf did the trick.
0
 
Jeffrey CoachmanCommented:
;-)
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now