Microsoft KB Archive/289670

= How to synchronize two combo boxes on a form in Access 2002 or in Access 2003 =

Article ID: 289670

Article Last Modified on 1/31/2007

-

APPLIES TO


 * Microsoft Office Access 2003
 * Microsoft Access 2002 Standard Edition

-



This article was previously published under Q289670



Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

For a Microsoft Access 2000 version of this article, see 209595.



For a Microsoft Access 97 version of this article, see 97624.



SUMMARY
This article describes how to synchronize two combo boxes so that when you select an item in the first combo box, the selection limits the choices in the second combo box.

Note This article explains a technique that is demonstrated in the sample file, FrmSmp00.mdb. For additional information about how to obtain this sample file, click the following article number to view the article in the Microsoft Knowledge Base:

233324 ACC2000: Microsoft Access 2000 Sample Forms Database Available in Download Center



MORE INFORMATION
The following example uses the sample database Northwind.mdb. The first combo box lists the available product categories, and the second combo box lists the available products for the category selected in the first combo box:

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.  Open the sample database Northwind.mdb.  Create a new form that is not based on any table or query with the following combo boxes, and then save the form as Categories And Products.   Combo Box 1 ---  Name:          Categories RowSourceType: Table/Query RowSource:    Categories ColumnCount:  2 ColumnWidths: 0&quot;;1&quot; BoundColumn:  1 AfterUpdate:  [Event Procedure]

Combo Box 2 --  Name:          Products RowSourceType: Table/Query ColumnWidths: 2&quot; Width:        2&quot; NOTE: If you are in an Access project, the RowSourceType will be Table/View/StoredProc.   Add the following code to the AfterUpdate event procedure of the Categories combo box: Me.Products.RowSource = &quot;SELECT ProductName FROM&quot; & _ &quot; Products WHERE CategoryID = &quot; & Me.Categories & _ &quot; ORDER BY ProductName&quot; Me.Products = Me.Products.ItemData(0)  View the Categories And Products form in Form view. Note that when you select a category in the first combo box, the second combo box is updated to list only the available products for the selected category.