Results 1 to 2 of 2

Thread: dynamic filter

  1. #1
    Join Date
    Oct 2012
    Location
    Middle Georgia
    Posts
    11

    Unanswered: dynamic filter

    I have a form I am trying to filter using "dynamic" criteria (not sure what else to call it). The user can select what field they want to filter on from a combobox and then what criteria from that field. I am not sure of the syntax for the filter. This is what I have. When I click the button, it filters out everything.

    Code:
    Private Sub btnFilter_Click()
    If Not IsNull(Me.cboSrchField1.Value) Then
        Master.Form.Filter = " & me.cboSrchField1 & " = " & Me.cbofilterfld1 & "
        Master.Form.FilterOn = True
    End If
    
    End Sub

  2. #2
    Join Date
    Jan 2005
    Posts
    146
    Try:
    Code:
    Private Sub btnFilter_Click()
    If Not IsNull(Me.cboSrchField1.Value) Then
        Master.Form.Filter = "[" & me.cboSrchField1 & "]=" & Me.cbofilterfld1 
        Master.Form.FilterOn = True
    End If
    
    End Sub
    This is assuming the value is numeric. If it is text or a date you will need to change it:
    Text:
    Code:
    Master.Form.Filter = "[" & me.cboSrchField1 & "]='" & Me.cbofilterfld1 & "'"
    Date:
    Code:
    Master.Form.Filter = "[" & me.cboSrchField1 & "]=#" & Me.cbofilterfld1 & "#"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •