Results 1 to 5 of 5
  1. #1
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Combo Box Filter (2003 / 2000)

    I open a form with a Where Condition that imposes a filter. Everything works fine except in the form header where I have a combo box that's used to select a record. But the data source for the combo box doesn't incorporate the filter so it lists all the records instead of just the filtered ones. How do I limit the combo box to the filtered records?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Combo Box Filter (2003 / 2000)

    You can change the Row Source of the combo box in the On Open or On Load event of the form. You could pass the filter string in the OpenArgs argument of DoCmd.OpenForm, and use it in the On Open/On Load event procedure to assemble the SQL string for the row source. Or if you already use the OpenArgs argument for something else, you can store the filter string in a global variable. Post back if you need more detailed help.

  3. #3
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Combo Box Filter (2003 / 2000)

    Thanks again. I am using openargs for something else, but creating a global variable looks like a good approach.

  4. #4
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Combo Box Filter (2003 / 2000)

    I guess I do need help with the syntax for setting the Row Source with a filter in a combo box on the form load event.

    I need something like:

    If variable = true then
    Row Source Filter = "filter setting"
    Else
    Row Source Filter = "different filter"
    End If

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Combo Box Filter (2003 / 2000)

    You will have to assemble an SQL string. Let's say that your combo box is named cboSelect and that it has 3 columns, coming from TableA.
    The global variable that you populate with the WhereCondition is named strFilter.

    Dim strSQL As String

    If Not strFilter = "" Then
    strSQL = "SELECT Field1, Field2, Field3 FROM TableA WHERE " & strFilter
    Me.cboSelect.RowSource = strSQL
    End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •