Share via

Two Combo Boxes to Produce a Filtered Subform Datasheet

Patrick Snyder 5 Reputation points
2025-12-22T20:27:13.5933333+00:00

I have a form that has a subform. The subform has a datasheet on it. There's a Combo box that filters the datasheet, on the subform.

How do I create more than one combo box that allows the user to filter the datasheet by more than one field?

Example: my table has many fields; two of the fields are labeled color and size. Right now, my combo box filters by color but I also want to filter by size. So, I want my form to have two different combo boxes to help filter the datasheet.

It would be nice that the user can filter by color or size or by color than by size.

How can I do this?

Microsoft 365 and Office | Access | Other | Windows
0 comments No comments

7 answers

Sort by: Most helpful
  1. Dora-T 13,745 Reputation points Microsoft External Staff Moderator
    2026-01-21T11:27:44.1533333+00:00

    Hi @Patrick Snyder

    Thank you for your response. 

    Based on your screenshot, the issue is likely caused by a syntax error in the SQL statement. It appears that some spaces between keywords are missing, so Access is not able to interpret it correctly. 

    Please try updating it using the Zoom window as follows:

     -Open the Material form in Design View.

     -Select the second combo box (RFQ).

    -Open the Property Sheet and go to the Data tab.

     -Right-click in the Row Source field and choose Zoom….

     -In the Zoom window, replace the existing text with the corrected SQL, then click OK.

    SELECT DISTINCT RFQ_num
    FROM Data
    WHERE Cty = Forms!Material!Combo5
    ORDER BY RFQ_num;
    

     -Save the form, close it, and reopen it.

     User's image

    User's image

    This should resolve the syntax error and allow the RFQ combo box dropdown to display the correct values based on the selected Country.

     Please try this on your side and let me know if it works.

    Was this answer helpful?

    1 person found this answer helpful.

  2. Ken Sheridan 3,571 Reputation points
    2025-12-24T16:43:13.6566667+00:00

    Lets assume that the subform's table has columns Color and Size each of which references single column Colors and Sizes tables respectively. The RowSouce properties for the two unbound combo boxes in the subform's header, named cboFindColor and cboFindSize for instance, would thus be:

    SELECT Color FROM Colors ORDER BY Color;
    

    and:

    SELECT Size FROM Sizes ORDER BY Size;
    

    The RecordSource property of the subform would be along these lines:

    SELECT *
    FROM Widgets
    WHERE (Color = Form!cboFindColor 
        OR Form!cboFindColor IS NULL)
    AND (Size = Form!cboFindSize
        OR Form!cboFindSize IS NULL)
    

    Note how, as the combo boxes are in the subform, in the above the Form property is used rather than referencing the subform by name. In the AfterUpdate event procedure of each combo box requery the form with:

    Me.Requery
    

    Was this answer helpful?

    1 person found this answer helpful.

  3. Patrick Snyder 5 Reputation points
    2025-12-29T01:39:45.8433333+00:00

    Hi, Dora,

    I've been out of the office on holiday vacation. I may get a chance to review and try it later this week.

    Was this answer helpful?


  4. Dora-T 13,745 Reputation points Microsoft External Staff Moderator
    2025-12-23T06:38:44.9466667+00:00

    Hi Patrick Snyder

    Thank you for reaching out to the Microsoft Q&A Forum. 

    Based on your description, I understand that you’re trying to filter a datasheet subform using more than one combo box, allowing users to filter by color, size, or both. 

    At the moment, I’m actively testing a solution suggested by Q&A Assist. However, the initial results indicate that this approach does not fully work as expected, so I need a bit more time to continue testing and validating it further before sharing any next steps to avoid providing an inaccurate solution or causing unnecessary support delays. 

    Thank you for your patience and understanding. I’ll keep you posted whenever I have any confirmed updates. 

    If you have any additional details you’d like to share in the meantime, please feel free to let me know. 


    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?


  5. AI answer

    2025-12-22T20:27:24.8066667+00:00

    To create two combo boxes that allow users to filter a datasheet in a subform by multiple fields (like color and size), you can follow these general steps:

    1. Add Combo Boxes: Add two combo boxes to your main form. One will be for filtering by color and the other for filtering by size.
    2. Set Up Row Sources: For each combo box, set the Row Source to the appropriate field in your table. For example, the first combo box should have a Row Source that pulls distinct values from the color field, and the second combo box should pull values from the size field.
    3. Create a Filter Query: You will need to create a query that combines the filters from both combo boxes. This can be done using VBA or by setting the filter property of the subform based on the selections in the combo boxes.
    4. Implement Filtering Logic: In the AfterUpdate event of each combo box, write code that applies the filter to the subform. For example:
      • If both combo boxes have values, filter by both fields.
      • If only one combo box has a value, filter by that field only.
      • If neither combo box has a value, show all records.
    5. Refresh the Subform: After applying the filter, refresh the subform to display the filtered results.

    Here is a simple example of what the VBA code might look like in the AfterUpdate event of the combo boxes:

    Private Sub cboColor_AfterUpdate()
        ApplyFilter
    End Sub
    
    Private Sub cboSize_AfterUpdate()
        ApplyFilter
    End Sub
    
    Private Sub ApplyFilter()
        Dim strFilter As String
        strFilter = ""
    
        If Not IsNull(Me.cboColor) Then
            strFilter = strFilter & "Color = '" & Me.cboColor & "'"
        End If
    
        If Not IsNull(Me.cboSize) Then
            If strFilter <> "" Then strFilter = strFilter & " AND "
            strFilter = strFilter & "Size = '" & Me.cboSize & "'"
        End If
    
        Me.subformName.Form.Filter = strFilter
        Me.subformName.Form.FilterOn = True
    End Sub
    

    This code constructs a filter string based on the selections in the combo boxes and applies it to the subform.

    By following these steps, users will be able to filter the datasheet by color, size, or both, enhancing the usability of your form.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.