Results 1 to 4 of 4
  1. #1
    paloma.rz is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Posts
    3

    Unhappy Filter with multiple values

    Hi guys! my problem is refered to filtering a subquery with a list box with multiple select items. I saved all the data in a string, separating the values with comas, and then set the filter. But it wont work when i select more than one value.


    The listbox has 3 strings to choose, "Ordinario", "integrazione", "Speciale", and the column name is "Categoria".
    For now my code looks like this:

    Private Sub btnSearch_Click()
    Dim varItem As Variant
    Dim strSearch As String
    Dim Task As String


    Me.DB_Milestone_subform.Form.FilterOn = False


    For Each varItem In Me!ListCategoria.ItemsSelected
    strSearch = strSearch & "," & Me!ListCategoria.ItemData(varItem)

    Next varItem


    If Len(strSearch) = 0 Then
    Task = "Select * from DB_Milestone"
    Else
    strSearch = Right(strSearch, Len(strSearch) - 1)
    MsgBox (strSearch)
    Task = "Select * from DB_Milestone where ([ID] in ( " & strSearch & " ))"
    'MsgBox (Task)
    End If

    'I created Task string but for now i couldnt use it on the filter


    Me.DB_Milestone_subform.Form.Filter = " Categoria = ( '" & strSearch & "')"
    Me.DB_Milestone_subform.Form.FilterOn = True


    'DoCmd.ApplyFilter Task


    'This part didnt even work. im new at programming


    End Sub

    Could anyone help me please??

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    You aren't using In for the filter, and text values need delimiters. This isn't exactly what you're doing, but building the filter would be the same:

    http://www.baldyweb.com/multiselect.htm

    note you need the text version.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Code:
    '----------------
    sub FilterData_Click()
    '----------------
    dim sWhere as strin 
    
    sWhere = "1=1"
    if not IsNUll(cboST) then sWhere = sWhere & " and [State]='" & cboST & "'"
    if not IsNUll(cboCity) then sWhere = sWhere & " and [city]='" & cboCity & "'"
    if not IsNUll(cboZip) then sWhere = sWhere & " and [ZipCode]='" & cboZip & "'"
    
    If sWhere = "1=1" Then
      Me.FilterOn = False
    Else
      Me.Filter = sWhere
      Me.FilterOn = True
    End If
    end sub

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Quote Originally Posted by ranman256 View Post
    Code:
    '----------------
    sub FilterData_Click()
    '----------------
    dim sWhere as strin 
    
    sWhere = "1=1"
    if not IsNUll(cboST) then sWhere = sWhere & " and [State]='" & cboST & "'"
    if not IsNUll(cboCity) then sWhere = sWhere & " and [city]='" & cboCity & "'"
    if not IsNUll(cboZip) then sWhere = sWhere & " and [ZipCode]='" & cboZip & "'"
    
    If sWhere = "1=1" Then
      Me.FilterOn = False
    Else
      Me.Filter = sWhere
      Me.FilterOn = True
    End If
    end sub
    I can't see how this relates to the issue at hand.
    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: 2
    Last Post: 02-20-2017, 11:28 PM
  2. Replies: 3
    Last Post: 10-30-2016, 05:50 AM
  3. Filter out values that do not have max value
    By bigchicagobob in forum Queries
    Replies: 1
    Last Post: 03-20-2014, 12:01 PM
  4. Replacing many values at once in a multiple values checkbox field.
    By ConfusedDatabaseDesigner in forum Forms
    Replies: 2
    Last Post: 07-20-2012, 08:58 AM
  5. filter table by multiple values
    By TheShabz in forum Access
    Replies: 4
    Last Post: 11-01-2011, 05:34 PM

Tags for this Thread

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