Sample database: CascadingComboBoxes.zip (62 KB)
Combo boxes and list boxes are a great way to control user experience by limiting the values that a user can choose to a known list.
In Microsoft Access, a common need is to have multiple combo boxes or list boxes on a form, and to have the selection in one combo box limit the choices in a second combo box. For example, an Address form containing Country and State lookups. When you select a country, its list of states appear.
Our this sample database, we have a list of species, both plants and animals, categorized by their taxonomic rank (kingdom, phylum, class, order, family, genus, then species).
If you select the value "Animal" from the Kingdom combo box, the Phylum combo box is updated to show Animal phylums only. The Species list box is also filtered by your selection.
This is known as cascading combo boxes or synchronized combo boxes.
To create the cascading combo box, we add code in the "AfterUpdate" event for the Kingdom combo box, to update the RowSource property of the Phylum combo box based on the selected Kingdom.
' Set the Phylum combo box to be limited by the selected Kingdom
Me.cboPhylumID.RowSource = "SELECT PhylumID, PhylumName " & _
"FROM tblPhylum " & _
"WHERE KingdomID = " & Nz(Me.cboKingdomID) & _
"ORDER BY PhylumName"
Additionally, we add code to update the contents of the Species list box:
' Limit the Species list box Me.lstSpeciesID.RowSource = "SELECT SpeciesName, Description " & _ "FROM qryTaxonomy " & _ "WHERE KingdomID = " & Me.cboKingdomID ' Refresh the list box Me.lstSpeciesID.Requery
After updating the RowSource property, use the list box's Requery method to re-load the data in the ListBox.
There is sometimes confusion between the terms RecordSource and RowSource. Both are properties that can contain a table, query, or SQL string.
Microsoft Resource: How to: Synchronize Two Combo Boxes on a Form
Strategic Overview
Microsoft Access within an Organization's Database Strategy
How many simultaneous Microsoft Access users?
Blaming Microsoft Access instead of the Developer
Microsoft Access Version Feature Differences
Microsoft Access Versions, Service Packs and Updates
Microsoft Office 365 Access Update Version Releases
Top 14 Features Added with MS Access 2007
Taking Over Legacy MS Access Databases
Winner of Every Best Access Add-in Award
Set AutoNumber Starting Number Other than 1
Avoid Unnecessary or Duplicate Indexes
Copy Command Button and Keep Picture
Module VBA to Forms and Controls
Subform Reference to Control Rather than Field
Suppress Page Headers and Footers on the First Page of Your Report
Annual Monthly Crosstab Columns
Add Buttons to the Quick Access Toolbar
Collapse the Office Ribbon for more space
Avoid Exits in the Body of a Procedure
Send Emails with DoCmd.SendObject
Error Handling and Debugging Techniques
Error Number and Description Reference
Remote Desktop Connection Setup
Terminal Services and RemoteApp Deployment
Missing Package & Deployment Wizard
Remove 'Save to SharePoint Site' Prompt from an Access Database
Class Not Registered Run-time Error -2147221164
Microsoft Access to SQL Server Upsizing Center
When and How to Upsize Access to SQL Server
SQL Server Express Versions and Downloads
Deploying MS Access Linked to SQL Azure
SQL Server Azure Usage and DTU Limits