Microsoft KB Archive/99937

= ACC: Base Combo Box on Parameter Query to Filter Values =

Article ID: 99937

Article Last Modified on 1/18/2007

-

APPLIES TO


 * Microsoft Access 1.0 Standard Edition
 * Microsoft Access 1.1 Standard Edition
 * Microsoft Access 2.0 Standard Edition
 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q99937



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



SUMMARY
This article show you how to filter values that appear in a combo box by basing the combo box on a parameter query.



MORE INFORMATION
Sometimes, you may want to limit the values that appear in a combo box. For example, you may want to show only suppliers whose names begin with a certain letter. Although Microsoft Access does not allow filters on combo boxes, if you base your combo box on a parameter query, you can filter the values by using a criteria clause.

This article describes the steps to create a combo box that displays only the suppliers that meet the criteria that you specify. The example uses the sample database Northwind.mdb (or Nwind.mdb in versions 1.x and 2.0).

 Open the sample database Northwind.mdb.  Create the following query based on the Suppliers table to use as the row source in the combo box:

     Query: Filtered Supplier List -     Type: Select Field: CompanyName Table: Suppliers Sort: Ascending Criteria: Like [My Criteria Box] & &quot;*&quot; NOTE: In versions 1.x and 2.0, there is a space in Company Name.   Create the following macro to update the combo box with new criteria:

     MacroName: CB Test Macro Action: Requery ControlName: My Combo Box   Create the following unbound form to test your controls:

     Form: TestForm --     Caption: Test Filtered Combo Box

Combo Box: Name: My Combo Box RowSourceType: Table/Query RowSource: Filtered Supplier List Text Box: Name: My Criteria Box After Update: CB Test Macro  Open TestForm in Form view and click the arrow on the combo box. Note that all suppliers appear in the list.</li> Type a single letter in My Criteria Box (for example, the letter E).</li> Click the arrow on the combo box. Note that only suppliers whose names begin with the letter &quot;E&quot; are displayed.</li> Type a new letter in My Criteria Box (for example, the letter P).</li> Click the arrow. Note that although the combo box value still shows a company starting with &quot;E&quot; (if you selected one), only suppliers whose names begin with the letter &quot;P&quot; are displayed in the list.</li></ol>

<div class="references_section">