Results 1 to 3 of 3
  1. #1
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    409

    Complex filtering

    hi, i use this procedure to filter various forms



    Code:
    Private Sub BuildFilt(FrmName As String)   Dim db As DAO.Database
       Dim rs As DAO.Recordset
       Dim rsFilt As DAO.Recordset
       Dim FiltStr As String
       Dim Wldcrd As String
       Dim Wldcrd2 As String
       Set db = CurrentDb
       Dim frm As Form
       If FrmName = "lista candidati" Then
          Set frm = Forms!contatti!
    [Lista Candidati].Form
       Else
          Set frm = Forms(FrmName)
       End If
       Me.SubFiltri.Form.OrderBy = "[Operatore]"
       Me.SubFiltri.Form.OrderByOn = True
       Set rs = Me.SubFiltri.Form.RecordsetClone
       rs.Filter = "[Active] = true"
       Set rsFilt = rs.OpenRecordset
       rsFilt.MoveFirst
       Do Until rsFilt.EOF
          If IsNull(rsFilt!Espressione) Then
             Select Case rsFilt!TipoCampo
                Case "text", "memo"
                   Wldcrd = """"
                   Wldcrd2 = """"
                Case "long", "double", "boolean"
                   Wldcrd = ""
                   Wldcrd2 = ""
                Case "date"
                   Wldcrd = "#"
                   Wldcrd2 = "#"
                Case Else
                   Wldcrd = ""
                   Wldcrd2 = ""
             End Select
             Select Case rsFilt!Criterio
                Case "Comincia con"
                   FiltStr = FiltStr & rsFilt!Operatore & " [" & rsFilt!Campo & "] LIKE """ & rsFilt!valore1 & "*"" "
                Case "non Comincia con"
                   FiltStr = FiltStr & rsFilt!Operatore & " [" & rsFilt!Campo & "] NOT LIKE """ & rsFilt!valore1 & "*"" "
                Case "Finisce con"
                   FiltStr = FiltStr & rsFilt!Operatore & " [" & rsFilt!Campo & "] LIKE ""*" & rsFilt!valore1 & """ "
                Case "non Finisce con"
                   FiltStr = FiltStr & rsFilt!Operatore & " [" & rsFilt!Campo & "] NOT LIKE ""*" & rsFilt!valore1 & """ "
                Case "contiene"
                   FiltStr = FiltStr & rsFilt!Operatore & " [" & rsFilt!Campo & "] LIKE ""*" & rsFilt!valore1 & "*"" "
                Case "non contiene"
                   FiltStr = FiltStr & rsFilt!Operatore & " [" & rsFilt!Campo & "] NOT LIKE ""*" & rsFilt!valore1 & "*"" "
                Case "="
                   FiltStr = FiltStr & rsFilt!Operatore & " [" & rsFilt!Campo & "] = " & Wldcrd & rsFilt!valore1 & Wldcrd2 & " "
                Case "<>"
                   FiltStr = FiltStr & rsFilt!Operatore & " [" & rsFilt!Campo & "] <> " & Wldcrd & rsFilt!valore1 & Wldcrd2 & " "
                Case ">"
                   FiltStr = FiltStr & rsFilt!Operatore & " [" & rsFilt!Campo & "] > " & Wldcrd & rsFilt!valore1 & Wldcrd2 & " "
                Case "<"
                   FiltStr = FiltStr & rsFilt!Operatore & " [" & rsFilt!Campo & "] <" & Wldcrd & rsFilt!valore1 & Wldcrd2 & " "
                Case "vuoto"
                   FiltStr = FiltStr & rsFilt!Operatore & " [" & rsFilt!Campo & "] is null "
                Case "non vuoto"
                   FiltStr = FiltStr & rsFilt!Operatore & " [" & rsFilt!Campo & "] is not null "
                Case "tra"
                   FiltStr = FiltStr & rsFilt!Operatore & " [" & rsFilt!Campo & "] Between " & Wldcrd & rsFilt!valore1 & Wldcrd2 & " and " & Wldcrd & rsFilt!Valore2 & Wldcrd2 & " "
                Case "non compreso tra"
                   FiltStr = FiltStr & rsFilt!Operatore & " [" & rsFilt!Campo & "] NOT Between " & Wldcrd & rsFilt!valore1 & Wldcrd2 & " and " & Wldcrd & rsFilt!Valore2 & Wldcrd2 & " "
             End Select
          Else
             FiltStr = FiltStr & rsFilt!Operatore & " (" & rsFilt!Espressione & ") "
          End If
          Debug.Print (FiltStr)
          rsFilt.MoveNext
       Loop
    
    
       frm.Filter = FiltStr
       frm.FilterOn = True
       Me.SubFiltri.Form.OrderBy = "[Campo],[criterio]"
       Me.SubFiltri.Form.OrderByOn = True
       rsFilt.Close
       Set rsFilt = Nothing
       Set rs = Nothing
       MinimizeBTN_Click
    the part that gives me trouble is this one

    Code:
                Case "="
                   FiltStr = FiltStr & rsFilt!Operatore & " [" & rsFilt!Campo & "] = " & Wldcrd & rsFilt!valore1 & Wldcrd2 & " "
    rsFilt!Valore1 is a textbox in my subform (i use form.recordsetclone), where are all the criteria. Usually is a value field, like a number, date, text etc etc and it works fine. My question is: instead of placing a value i'd like to use a control, maybe a combobox in main form.

    so, rsFilt!valore1 instead of being a text (maybe) should be something like "forms!filiali!cercacittāCB".

    but the filter do not consider the text in the combobox, just set the field i want to filter to "forms!filiali!cercacittāCB", that's not a value i want to search

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Try Eval() function.

    Eval(rsFilt!valore1)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    409
    that's it!

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

Similar Threads

  1. Complex filtering problem
    By KelliganP in forum Queries
    Replies: 6
    Last Post: 01-05-2021, 12:09 PM
  2. Really complex IIf
    By Nanuaraq in forum Queries
    Replies: 3
    Last Post: 03-19-2019, 07:38 AM
  3. Complex Query Help
    By Degs29 in forum Queries
    Replies: 9
    Last Post: 05-31-2013, 01:12 PM
  4. Complex Criteria
    By Kapelluschsa in forum Queries
    Replies: 7
    Last Post: 05-23-2011, 03:45 PM
  5. Replies: 3
    Last Post: 01-14-2010, 10:42 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