Results 1 to 2 of 2
  1. #1
    Bkper087 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    May 2014
    Posts
    81

    Using VBA and multiple combo boxes to filter a subform

    I have the code below set-up on a combo box that filters a subform. The problem I'm running into is I have this set-up on multiple combo boxes (with different combo box names, etc.). The filters seemed to work fine at first, but now that I've built out the database more, the filters are canceling each other out. I trigger the first one and it works fine. I trigger the next one and it filters what is expected for the second combo box, but it cancels the first filter in the process. Any suggestions on how to fix this?


    Private Sub cboCostCenter_AfterUpdate()


    If Len(Me.cboCostCenter & vbNullString) > 0 Then
    Me![frmEntry_sub].Form.Filter = "[Entry_CostCenterIDfk] = " & Me.cboCostCenter
    Else
    Me![frmEntry_sub].Form.Filter = "[Entry_CostCenterIDfk] = 0"
    End If
    Me![frmEntry_sub].Form.FilterOn = True


    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Along the lines of:

    Code:
        If Len(Me.cmbArrangeCustomer & vbNullString) > 0 Then
            strWhere = "GroupID = '" & Me.cmbArrangeCustomer & "' AND "
        End If
    
        If Len(Me.cmbQuotedBy & vbNullString) > 0 Then
            strWhere = strWhere & "Quoted = '" & Me.cmbQuotedBy & "' AND "
        End If
    
        If Len(strWhere) > 0 Then
            strWhere = Left(strWhere, Len(strWhere) - 5)
            'code here to set your filter
        End If
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 11-21-2017, 03:10 PM
  2. Filter with multiple Combo boxes
    By dotcanada in forum Access
    Replies: 3
    Last Post: 09-01-2016, 01:19 PM
  3. Replies: 3
    Last Post: 09-28-2015, 08:17 PM
  4. Filter subform with two combo boxes
    By dotcanada in forum Forms
    Replies: 4
    Last Post: 07-25-2015, 05:20 PM
  5. Replies: 9
    Last Post: 07-03-2014, 12:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums