Solved

How to have 3 cascading combo boxes work off each other

Posted on 2014-02-07
10
572 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 35

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 35

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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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 35

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 35

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

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…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

803 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