Results 1 to 6 of 6
  1. #1
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305

    Having difficulty with button to apply multiple filters


    I have a DB full of customer complaints and I am trying to use a button to filter down to a certain subset of entries in a form. I want the button to filter to "in progress" complaints, along with entries from two specific categories. My code is below:

    Code:
    Private Sub btnFilter_Click()    Me.Filter = "[Status]= 'In Progress'"
        Me.Filter = [Category]= 'Billing' or [Category] = 'Cleanliness'"
        DoCmd.SetOrderBy "[ComplaintDate] ASC"
        Me.FilterOn = True
    End Sub
    Using the above code does not apply the 'status' filter. Any suggestions on how to retool this?

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Could you please try this:
    Code:
    Private Sub btnFilter_Click()
    Dim sFilter as string
    sFilter="[Status]= 'In Progress' AND [Category] IN ('Billing','Cleanliness')"    
    'Me.Filter = "[Status]= 'In Progress'"
    'Me.Filter = [Category]= 'Billing' or [Category] = 'Cleanliness'"
    DoCmd.SetOrderBy "[ComplaintDate] ASC"
    Me.Filter=sFilter    
    Me.FilterOn = True
    End Sub
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Code:
    sub btnFind_click()
    sWhere = "1=1"
    if not isnull(cboState) then   sWhere = sWhere & " and [state]='" & cboState & "'"
    if not IsNull(txtName) then    sWhere = sWhere & " and [Name]='" & txtName & "'"
    if not IsNull(cboGender) then    sWhere = sWhere & " and [Gender]='" & cboGender & "'"
    
     'then filer
    if sWhere = "1=1" then
       me.filterOn = false
    else
       me.filter = sWhere
       me.filterOn = true
    endif
    end sub

  4. #4
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    Quote Originally Posted by Gicu View Post
    Could you please try this:
    Code:
    Private Sub btnFilter_Click()
    Dim sFilter as string
    sFilter="[Status]= 'In Progress' AND [Category] IN ('Billing','Cleanliness')"    
    'Me.Filter = "[Status]= 'In Progress'"
    'Me.Filter = [Category]= 'Billing' or [Category] = 'Cleanliness'"
    DoCmd.SetOrderBy "[ComplaintDate] ASC"
    Me.Filter=sFilter    
    Me.FilterOn = True
    End Sub
    Cheers,
    That worked!! Thank you!!

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #6
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    So what if you later decide you want to add more status' or categories - more buttons?
    At that point, might be better to use combos or listboxes, depending on the number of options and combinations you want to create.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 4
    Last Post: 06-01-2017, 01:26 AM
  2. Apply multiple filters to subform
    By Elwood07 in forum Forms
    Replies: 10
    Last Post: 07-06-2015, 12:17 AM
  3. Replies: 7
    Last Post: 11-01-2013, 09:14 AM
  4. Combining multiple toggle button filters
    By jasdem in forum Access
    Replies: 4
    Last Post: 09-18-2013, 10:29 AM
  5. Apply Multiple filters
    By spitfire122 in forum Access
    Replies: 2
    Last Post: 07-01-2011, 10:02 AM

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