473,396 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Limiting the values of a combo box using IIF in query criteria

Hello -

I am trying to limit the options that show in a combo box based on the value of another field.

In the design view of my query, I have the following criteria in the ReferralRole_ID field:
Expand|Select|Wrap|Line Numbers
  1. =IIf([Form]![f_MainReferralForm]![ActivityType_ID]=9,(1 Or 2 Or 7),(3 Or 7))
  2.  
This translates to the following SQL:

Expand|Select|Wrap|Line Numbers
  1. SELECT t_ReferralRoles_LU.ReferralRole_ID, t_ReferralRoles_LU.ReferralRole
  2. FROM t_ReferralRoles_LU
  3. WHERE (((t_ReferralRoles_LU.ReferralRole_ID)=IIf([Form]![f_MainReferralForm]![ActivityType_ID]=9,((t_ReferralRoles_LU.ReferralRole_ID)=1 Or (t_ReferralRoles_LU.ReferralRole_ID)=2 Or (t_ReferralRoles_LU.ReferralRole_ID)=7),((t_ReferralRoles_LU.ReferralRole_ID)=3 Or (t_ReferralRoles_LU.ReferralRole_ID)=7))))
  4. ORDER BY t_ReferralRoles_LU.ReferralRole_ID;
  5.  
I am getting zero records in my combo.

If I just put < 1 OR 2 OR 7 > in the criteria, it works fine.

Not sure if the IIF statement is coded correctly.

Many thanks
Sandra
Dec 21 '11 #1

✓ answered by NeoPa

Try for line #3 (The WHERE clause) :

Expand|Select|Wrap|Line Numbers
  1. WHERE (([Form]![f_MainReferralForm]![ActivityType_ID]=9) AND ([ReferralRole_ID] In(1,2,7))
  2.    OR  ([Form]![f_MainReferralForm]![ActivityType_ID]<>9) AND ([ReferralRole_ID] In(3,7)))

8 1842
Rabbit
12,516 Expert Mod 8TB
What it sounds like you're looking for is along the lines of this:

If Activity Type is 9, then Referral Role ID can be 1, 2, or 7. Otherwise Referral Role ID can be 3 or 7. Is that correct?
Dec 21 '11 #2
Hello Rabbit,

Yes, that is what I am trying to accomplish.
Dec 21 '11 #3
NeoPa
32,556 Expert Mod 16PB
Try for line #3 (The WHERE clause) :

Expand|Select|Wrap|Line Numbers
  1. WHERE (([Form]![f_MainReferralForm]![ActivityType_ID]=9) AND ([ReferralRole_ID] In(1,2,7))
  2.    OR  ([Form]![f_MainReferralForm]![ActivityType_ID]<>9) AND ([ReferralRole_ID] In(3,7)))
Dec 21 '11 #4
Works Perfectly! I was not aware of the In(x,y, ...) option.

Many thanks! :-)
Dec 21 '11 #5
PS - I presume IN = includes?
Dec 21 '11 #6
NeoPa
32,556 Expert Mod 16PB
Not exactly.
Expand|Select|Wrap|Line Numbers
  1. WHERE [A] In(X,Y,Z)
This could be read out as :
Where the value of [A] is found in the list of X,Y,Z.

It can work with any type of value. Not just numeric but also Dates, Strings etc.
Dec 21 '11 #7
Thanks for the clarification - can think of lots of ways to use this!
s-
Dec 21 '11 #8
NeoPa
32,556 Expert Mod 16PB
Indeed :-)

In() and Like can be very powerful constructs indeed.

Have fun.
Dec 21 '11 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: keliie | last post by:
Hello Just a quick question that I've spent a few hours trying to solve with no luck (although one would think this should be fairly easy). I have a form with a subform. The subform is based...
3
by: ericargent | last post by:
Hi I'm using Acces 2003 I have Query where the several parameters for the criteria are supplied from a form. One parameter source is a combo box. What I am trying to do is if: An item is...
4
by: candide_sh | last post by:
Hi, I have a combobox cbosaSAK_FKEY with these values: 1 2 3 The query criteria has to be changed into: 1 =1
2
by: cmartin1986 | last post by:
First of all I want to thank all of you that have helped me in the past this is an awesome fourm. My problem today is I have a database that builds charts that are viewed by a large group every...
0
VbaNewbee
by: VbaNewbee | last post by:
I have a form with a few filters. Once the user clicks "search button", the code first evaluates my filters, then shows the query results in a List Box" titled backschedule. I have a few text...
4
by: tbeers | last post by:
Is there a method to pass along a criteria argument directly to the query criteria rather than through filtering a form or report? In other words, I would like to click a "print" button and in the...
1
by: didihynes | last post by:
Hi Guys, I'm in desparate need of help. I am producing a database for my dissertation and have got majorly stuck. I am currently creating a form in which the user will select a student from a...
8
by: limperger | last post by:
Hello everyone! First and foremost, my apologies for the title of the post. It is not very clarifying of what the problem is about, but I didn't know how to put it... My problem is as follows: I...
1
by: Coll | last post by:
I have a database that produces different "cuts" of data for the user to export into excel. The database essentially opens queries using different criteria to filter the data as the user wants it....
9
ajhayes
by: ajhayes | last post by:
Hello everyone, This is my first time posting here and I'm hoping someone can help me out. I'm a relative newbie to Access and am pretty much learning as I go along, so please bear with me. ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.