none
VBA FOR UNBOUND COMBO BOX TO FIND RRS feed

  • Question

  • HI all:

    I have an unbound combo box, cbo.Category, in a form header.

    I'm trying to put together the VBA so I can find from the combo.

    1. The combo is unbound & contains both FK & text from a lookup table (luCategory,PK_Cat and Category). The lookup table is included in the form's datasource.

    2. I want to use After Update VBA to find all records of a certain category, but it's not quite working:

    Private Sub cboCategory_AfterUpdate()
    
    'perform find from unbound combo box
    
    On Error GoTo Error_Handler:
    
    
    Dim strWhere As String
    
    strWhere = strWhere & _
       IIf(IsNull(Me.cboCategory), "", " And PK_Cat = Me.cboCategory ")
       
    
    Me.Filter = strWhere
    Me.FilterOn = True
    
    Exit Sub
    
    Error_Handler:
        MsgBox Err.Number & " " & Err.Description
    
    End Sub

    Thanks!


    A. Wolf

    Friday, August 11, 2017 6:57 PM

Answers

  • Hi,

    What happens if you simply use?

    strWhere = "PK_Cat='" & Me.cboCategory & "'"

    • Proposed as answer by Terry Xu - MSFT Monday, August 14, 2017 6:18 AM
    • Marked as answer by amywolfie Saturday, August 19, 2017 6:10 PM
    Friday, August 11, 2017 7:04 PM