Results 1 to 1 of 1
  1. #1
    Join Date
    Oct 2013
    Posts
    23

    Unanswered: Filtering on multiple fields and two comboboxes

    The strFilter results in the following, but will not carry through to the Me.Filter, any ideas why?
    strFilter = "'20410' OR 'A20000' OR 'A20400'"

    Code:
    Private Sub Image_OffsetFilterButton_Click()
    Dim strFilter As String
    strFilter = "'A20410'"
       '/ see if there is data in Field Box Text907, if so add it to the filter
        If Me!Text907 & vbNullStr <> vbNullStr Then
       strFilter = strFilter & " OR " & "'" & "A20000" & "'"
    End If
       If Me!Text910 & vbNullStr <> vbNullStr Then
      ' If FieldB is of Text type, use the ' delimiter
       strFilter = strFilter & " OR " & "'" & "A20024" & "'"
    End If
      If Me!Text911 & vbNullStr <> vbNullStr Then
     ' If FieldB is of Text type, use the ' delimiter
      strFilter = strFilter & " OR " & "'" & "A20400" & "'"
    End If
     '/<etc>
    
    
    If strFilter <> "" Then
    ' trim off leading "OR"
      Me.Filter = "[Account] = strFilter AND [BU] = 'B50931'"
      Me.FilterOn = True
    Else
      Me.Filter = ""
      Me.FilterOn = False
    End If
    End Sub
    SOLVED
    Code:
    Private Sub Image_OffsetFilterButton_Click()
    Dim strFilter As String
    strFilter = ""
    '/ see if there is data in Field Box Text907, if so add it to the filter
    If Me!Text907 & vbNullStr <> vbNullStr Then
      strFilter = strFilter & " OR [ACCOUNT] = '" & Me.Text907 & "'"
    End If
    If Me!Text910 & vbNullStr <> vbNullStr Then
       '/ If FieldB is of Text type, use the ' delimiter
       strFilter = strFilter & " OR [ACCOUNT] = '" & Me.Text910 & "'"
       End If
    If Me!Text911 & vbNullStr <> vbNullStr Then
       '/ If FieldB is of Text type, use the ' delimiter
       strFilter = strFilter & " OR [ACCOUNT] = '" & Me.Text911 & "'"
    End If
    '/<etc>
    
       If strFilter <> "" Then
       '\ trim off leading "OR"
       Me.Filter = Mid(strFilter, 4)
       Me.FilterOn = True
    Else
       Me.Filter = "[BU] = [Forms]![Frm_Main]![Frm_Main_TextBox_Display_BU_Number_HIDDEN].Value"
       Me.FilterOn = False
    End If
    End Sub
    Last edited by T-Rex19; 12-12-13 at 18:59. Reason: Making Progress

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
  •