Ok, so now I have coded what I think should work for my listboxes and it does not. When I click it does nothing. No processing of anything.
I have 11 multi-listboxes and want to collect what the user selects from each one and then use it to run my query. The query only uses 4 of the listbox items and then 4 other items that I have in the query. I want to be able to display this in the same form or perhaps a subform. Here is my code:
I have 11 multi-listboxes and want to collect what the user selects from each one and then use it to run my query. The query only uses 4 of the listbox items and then 4 other items that I have in the query. I want to be able to display this in the same form or perhaps a subform. Here is my code:
Code:
Private Sub command8_click()
' Update the record source
If BuildFilter = "" Then
Me.frmQual_Sub.Form.RecordSource = "select * from qualq1 where " & BuildFilter
End If
'Requery the subform
Me.frmQual_Sub.Requery
End Sub
Private Function BuildFilter() As Variant
Dim varWhere As Variant
varWhere = Null ' Main filter
If Me.List1 > "" Then
varWhere = varWhere & "[lob] LIKE """ & Me.List1 & "*"" AND "
End If
If Me.List2 > "" Then
varWhere = varWhere & "[yr] LIKE """ & Me.List2 & "*"" AND "
End If
If Me.List3 > "" Then
varWhere = varWhere & "[mth] LIKE """ & Me.List3 & "*"" AND "
End If
If Me.List4 > "" Then
varWhere = varWhere & "[st_cd] LIKE """ & Me.List4 & "*"" AND "
End If
If Me.List5 > "" Then
varWhere = varWhere & "[bus_unit] LIKE """ & Me.List5 & "*"" AND "
End If
If Me.List6 > "" Then
varWhere = varWhere & "[prod_nm] LIKE """ & Me.List6 & "*"" AND "
End If
If Me.list7 > "" Then
varWhere = varWhere & "[category_condition] LIKE """ & Me.list7 & "*"" AND "
End If
If Me.list8 > "" Then
varWhere = varWhere & "[measure] LIKE """ & Me.list8 & "*"" AND "
End If
If Me.list9 > "" Then
varWhere = varWhere & "[sub_measure] LIKE """ & Me.list9 & "*"" AND "
End If
If Me.List10 > "" Then
varWhere = varWhere & "[comm_lvl] LIKE """ & Me.List10 & "*"" AND "
End If
If Me.List11 > "" Then
varWhere = varWhere & "[comm_type] LIKE """ & Me.List11 & "*"" AND "
End If
'Check if there is a filter to return...
If IsNull(varWhere) Then
varWhere = "''"
Else
' strip off last "AND" in the filter
If Right(varWhere, 5) = " AND " Then
varWhere = Left(varWhere, Len(varWhere) - 5)
End If
End If
BuildFilter = varWhere
End Function