The title is maybe a little vague.
What I'm trying to do is creating a macro to filter data in a subform.
But what I'm trying I can't find anywhere.
First I want multiple filters on 1 field. So when there are multiple statements true I get all the records that meet the statements.
This works fine on itself.
But after this I want that kind of filter on multiple fields, but with different statements. So when multiple statements on 1 filter and multiple statements on an other filter are true I get all the records of all the statements.
I wrote the following code, but it seems to go wrong with combining the two filters. Because it does filter the first statement but doen't wilter the second.
PS this code should get more filters when it works. But that should be just copy and paste.
What I'm trying to do is creating a macro to filter data in a subform.
But what I'm trying I can't find anywhere.
First I want multiple filters on 1 field. So when there are multiple statements true I get all the records that meet the statements.
This works fine on itself.
But after this I want that kind of filter on multiple fields, but with different statements. So when multiple statements on 1 filter and multiple statements on an other filter are true I get all the records of all the statements.
I wrote the following code, but it seems to go wrong with combining the two filters. Because it does filter the first statement but doen't wilter the second.
Code:
Public Sub FilterMacro()
Dim FilterString As String
Dim ProductFilter As String
Dim DriveFilter As String
Dim FeaturesFilter As String
Dim SWLFilter As String
Dim BoomFilter As String
Dim ProductLen As Long
Dim DriveLen As Long
Dim ingLen As Long
If Me.BH_Check = True Then
ProductFilter = ProductFilter & "([Product type] = 'BH') OR "
End If
If Me.GW_Check = True Then
ProductFilter = ProductFilter & "([Product type] = 'GW') OR "
End If
If Me.KB_Check = True Then
ProductFilter = ProductFilter & "([Product type] = 'KB') OR "
End If
If Me.RL_Check = True Then
ProductFilter = ProductFilter & "([Product type] = 'RL') OR "
End If
If Me.Other_Check = True Then
ProductFilter = ProductFilter & "([Product type] = 'Other') OR "
End If
ProductLen = Len(ProductFilter) - 4
If Not ProductLen <= 0 Then
ProductFilter = Left$(ProductFilter, ProductLen)
End If
If Me.DHC_Check = True Then
DriveFilter = DriveFilter & "([Drive type] = 'DHC') OR "
End If
If Me.EHC_Check = True Then
DriveFilter = DriveFilter & "([Drive type] = 'EHC') OR "
End If
If Me.EC_Check = True Then
DriveFilter = DriveFilter & "([Drive type] = 'EC') OR "
End If
If Me.NotSpecified_Check = True Then
DriveFilter = DriveFilter & "([Drive type] = 'Open') OR "
End If
If Me.Open_Check = True Then
DriveFilter = DriveFilter & "([Drive type] = 'Not Specified') OR "
End If
DriveLen = Len(DriveFilter) - 4
If Not DriveLen <= 0 Then
DriveFilter = Left$(DriveFilter, DriveLen)
End If
FilterString = ProductFilter & DriveFilter
lngLen = Len(FilterString)
If Not lngLen <= 0 Then
Me.Competitors_subform.Form.Filter = FilterString
Me.Competitors_subform.Form.FilterOn = True
End If
If Me.BH_Check = False And Me.GW_Check = False And Me.KB_Check = False And Me.RL_Check = False And Me.Other_Check = False Then
Me.Competitors_subform.Form.FilterOn = False
End If
End Sub
PS this code should get more filters when it works. But that should be just copy and paste.