?
Solved

How to have 3 cascading combo boxes work off each other

Posted on 2014-02-07
10
Medium Priority
?
604 Views
Last Modified: 2014-02-19
I attached my database for you to see what I am referring to.   Look at the top left of the Contact Form.   There are two drop down boxes.  The first one selects a category,  the second one selects the people based on the initial category. Turns out I need one to go in between those.  So I will need three.   The first will select a month, or Other.   The second one will then display WCF,  EPLI,  Cyber,  ADD,  or EPLI/Cyber.  But these need to be tied to the first drop down month.   Then the third box will generate the names based on the month and the product that falls into that month (first and Second box).  

I hope that makes sense.  This is a tough one being that I am beginner.
1.accdb
0
Comment
Question by:lehi52
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 38

Accepted Solution

by:
PatHartman earned 2000 total points
ID: 39843683
The RowSource query for combo2 needs to refer to combo1 -
Select ... From .... Where somefield = Forms!yourform!combo1
Combo3 needs to refer to combo2
Select ... From ... Where somefield = Forms!yourform!combo2

Then in the AfterUpdate event of each combo, requery the "lower" combos.

Afterupdate for combo1
Me.Combo2.Requery
Me.Combo3.Requery

AfterUpdate for combo2
Me.Combo3.Requery
0
 

Author Comment

by:lehi52
ID: 39844733
Is it possible to put it into that database I posted so I can see the sample.  Im not the greatest with code.  Or can you tell me where to put it.  Like on which event etc.
0
 
LVL 38

Expert Comment

by:PatHartman
ID: 39844830
I told you which events to use ---
The AfterUpdate event of each of the first two combos.  In the AfterUpdate event of combo1 you requery combos 2 and 3.  In the AfterUpdate event of combo 2, you requery combo3.  That's all the code you need.  Then you need to add criteria to the RowSource queries for combos 2 and 3 so they reference their "parent" combo.

There are other methods but they all take more code.
0
10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

 

Author Comment

by:lehi52
ID: 39846241
I added these to the after event with the code specific to those boxes.  

Afterupdate for combo1
Me.Combo2.Requery
Me.Combo3.Requery

AfterUpdate for combo2
Me.Combo3.Requery 

Open in new window


What do I do with the row source?
0
 

Author Comment

by:lehi52
ID: 39846273
Take a look at this.  Its zipped up.   The middle box returns numbers,  haven't figured out yet how to get it to show just the products available.  Then I need the final box to show the people that fit the second box criteria.  

What have I done wrong so far.  Thanks for your help.
Afterupdate for combo1
Me.Combo2.Requery
Me.Combo3.Requery

AfterUpdate for combo2
Me.Combo3.Requery 

Open in new window

2.accdb
0
 
LVL 38

Expert Comment

by:PatHartman
ID: 39846463
You need a lot of changes to your data model.  The relationships are pathological.  The correct solution for a relationship is for the child table to contain a foreign key to the parent table.  You have the child key in the parent table and the parent key in the child table.  Start by removing ContactID from risk level and level of hotness.  In the case of lookup tables, the "parent" table is the lookup table.

For ease of understanding, I recommend changing all the "ID" names to meaningful names such as HotnessID and RiskLevelID.  I would also use the same names for the FK values.  That makes it clear when you look at a table which fields are foreign keys (they end in ID) or primary keys.  I would also remove all the embedded spaces and special characters.  Doing this now will orphan any code or macros already created so everything would need to be modified and reconnected.

The RowSources for the combos don't seem to be related.  I'm not sure what they are actually doing so I can't make a recommendation.  An example would be acountry table, a state/provence table, and a city table.  The Country table contains Country, the State/Provence table contains State/provence and Country which is the FK to the Country table.  The City table contains City and State/Provence which is the FK to the StateProvence table.  It is the foreign keys that are used to control the value set at any one time and that is what the cascading is supposed to do.  Choose a Country and that limits the State/Provence list to those that contain the selected country.  Choose a state/provence and that limits the city list to cities in that state/provence
0
 

Author Comment

by:lehi52
ID: 39846484
Got working.  Awesome.  Thanks.  I have one final issue with the code.  The second combo box is showing ID numbers rather than desciptions.  How do I change that?

SELECT DISTINCT [CG Info].Products, [CG Info].Products, [Forms]![Contact Form]![select] AS Expr1
FROM [CG Info]
WHERE ((([Forms]![Contact Form]![select]) Is Null Or ([Forms]![Contact Form]![select])=[Targeting]))
ORDER BY [CG Info].Products;

Open in new window

0
 

Author Closing Comment

by:lehi52
ID: 39847487
It was a lot of help
0
 
LVL 38

Expert Comment

by:PatHartman
ID: 39847777
To get the combo to show a different column from the one that is bound, change the Column widths.  A value of 0 will hide a column.  So to show the third column in the RowSource, set the Column widths to:
0";0";2

That will hide the first two columns and show the third as 2" wide.
0
 

Author Comment

by:lehi52
ID: 39847838
Thank you.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

764 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