Hi all,
Using version 2007, I have an unbound form with cbos and a listbox to filter a report. I got this code off a Tek-Tips FAQ by Michael Red many years ago and have used it happily in many applications for my clients. Up to now, I haven’t had any problems. This is, however the first time I’ve ever used a listbox (and a mult-select one at that), and I don’t know how to adapt the code to pick up those multiple values for the strWhere variable (see below). I have searched ‘till I’m blue in the face for Michael’s original FAQ –can’t find it. So am begging the expert advice of you folks in the Forms forum.
Again, the listbox is a multi-select (simple), and here’s the code I’ve used for the cbos:
Any help you can give me will, as always, be greatly appreciated.
LM
Using version 2007, I have an unbound form with cbos and a listbox to filter a report. I got this code off a Tek-Tips FAQ by Michael Red many years ago and have used it happily in many applications for my clients. Up to now, I haven’t had any problems. This is, however the first time I’ve ever used a listbox (and a mult-select one at that), and I don’t know how to adapt the code to pick up those multiple values for the strWhere variable (see below). I have searched ‘till I’m blue in the face for Michael’s original FAQ –can’t find it. So am begging the expert advice of you folks in the Forms forum.
Again, the listbox is a multi-select (simple), and here’s the code I’ve used for the cbos:
Code:
Private Sub cmdPreview_Click()
Dim strWhere As String
If Len(Me.cboNature & "") > 0 Then
strWhere = strWhere & " AND IssueNature = '" & Me.cboNature & "'"
End If
If Len(Me.cboLocation & "") > 0 Then
strWhere = strWhere & " AND Location = '" & Me.cboLocation & "'"
End If
If Len(Me.cboCustomer & "") > 0 Then
strWhere = strWhere & " AND CustomerName = '" & Me.cboCustomer & "'"
End If
If Len(Me.cboCategory & "") > 0 Then
strWhere = strWhere & " AND ProductCategory = '" & Me.cboCategory & "'"
End If
If Len(strWhere & "") = 0 Then
' no options selected. Open report with no where condition
DoCmd.OpenReport "rptComplaintDetails", acViewPreview
Else
' remove first "AND" from where condition and pass across to report
DoCmd.OpenReport "rptComplaintDetails", acViewPreview, WhereCondition:=Mid(strWhere, 6)
End If
End Sub
Any help you can give me will, as always, be greatly appreciated.
LM