ACC: Base Combo Box on Parameter Query to Filter Values

Last reviewed: April 2, 1997
Article ID: Q99937
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0, 7.0, 97

SUMMARY

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

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

MORE INFORMATION

There may be situations in which you 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 using a criteria clause.

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

  1. Open the sample database Northwind.mdb.

  2. 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] & "*"
    
       NOTE: In versions 1.x and 2.0, there is a space in Company Name.
    
    

  3. Create the following macro to update the combo box with new criteria:

          MacroName: CB Test Macro
          ------------------------
    
             Action: Requery
             ControlName: My Combo Box
    
    

  4. 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
    
    

  5. Open TestForm in Form view and click the arrow on the combo box. Note that all suppliers appear in the list.

  6. Type a single letter in My Criteria Box (for example, the letter E).

  7. Click the arrow on the combo box. Note that only suppliers whose names begin with the letter E are displayed.

  8. Type a new letter in My Criteria Box (for example, the letter P).

  9. Click the arrow. Note that although the combo box value still shows a company starting with E (if you selected one), only suppliers whose names begin with the letter P are displayed in the list.

REFERENCES

For more information about creating combo boxes, search for "combo boxes," and then "creating and editing" using the Microsoft Access 97 Help Index.

For more information about creating criteria queries, search for "queries," and then "criteria, entering" using the Microsoft Access 97 Help Index.


Additional query words: limit drop down list box ddb
Keywords : FmsCmbo kbusage
Version : 1.0 1.1 2.0 7.0 97
Platform : WINDOWS
Hardware : X86
Issue type : kbinfo


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 2, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.