Solved

How to have 3 cascading combo boxes work off each other

Posted on 2014-02-07
10
593 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 37

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 37

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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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 37

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 37

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 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