Solved

How to have 3 cascading combo boxes work off each other

Posted on 2014-02-07
10
584 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
  • 6
  • 4
10 Comments
 
LVL 36

Accepted Solution

by:
PatHartman earned 500 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 36

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 36

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 36

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

680 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