Solved

How to have 3 cascading combo boxes work off each other

Posted on 2014-02-07
10
564 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 34

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 34

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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 34

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 34

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now