Gregof1976
Registered User.
- Local time
- Today, 11:55
- Joined
- Mar 28, 2011
- Messages
- 44
Hi All
I use two miltibox to filter sub-form. Generally filter work perfect but in one of the option when I mark some Model and Family is Null then I received error. Example of my code and simple data base is enclosed.
Your help will be appreciated ;-)
I use two miltibox to filter sub-form. Generally filter work perfect but in one of the option when I mark some Model and Family is Null then I received error. Example of my code and simple data base is enclosed.
Your help will be appreciated ;-)
Code:
Private Function BuildFilter() As Variant
Dim Model As Variant
Dim Family As Variant
Model = Null ' Subfilter used for Model
Family = Null ' Subfilter used for Family
[COLOR=seagreen]' Check for Models in multiselect list[/COLOR]
For Each varItem In Me.lstModel.ItemsSelected
Model = Model & " [TblCar.Model] = """ & _
Me.lstModel.ItemData(varItem) & """ OR "
Next
[COLOR=seagreen]'Test to see if we have subfilter for model[/COLOR]
If IsNull(Model) Then
[COLOR=seagreen]' do nothing[/COLOR]
Else
[COLOR=seagreen]' strip off last "OR" in the filter[/COLOR]
If Right(Model, 4) = " OR " Then
Model = Left(Model, Len(Model) - 4)
End If
[COLOR=seagreen]'Add parentheses around the subfilter[/COLOR]
varWhere = varWhere & "( " & Model & " ) And "
End If
[COLOR=seagreen]' Check for Familys in multiselect list[/COLOR]
For Each varItem In Me.lstFamily.ItemsSelected
Family = Family & " [TblCar.Family] = """ & _
Me.lstFamily.ItemData(varItem) & """ OR "
Next
[COLOR=seagreen]'Test to see if we have subfilter for Family[/COLOR]
If IsNull(Family) Then
[COLOR=seagreen]' do nothing[/COLOR]
Else
[COLOR=seagreen]' strip off last "OR" in the filter[/COLOR]
If Right(Family, 4) = " OR " Then
Family = Left(Family, Len(Family) - 4)
End If
[COLOR=seagreen]'Add parentheses around the subfilter[/COLOR]
varWhere = varWhere & "( " & Family & " ) "
End If
BuildFilter = varWhere
End Function
Attachments
Last edited: