Report Filtering

  • Thread starter Thread starter Damien
  • Start date Start date
D

Damien

How can I filter a report based on the records selected in
a multi-select ListBox?

Thanks


Damien
 
This example shows how to loop through the ItemsSelected collection of a
mult-select listbox, to build a string that you can use in the
WhereCondition of the OpenReport action.

Dim varItem As Variant 'Selected items
Dim strWhere As String 'String to use as WhereCondition
Dim lngLen As Long 'Length of string
Dim strDelim As String 'Delimiter for this field type.

strDelim = """" 'Delimiter appropriate to field type.
With Me.MyLisbox
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
strWhere = strWhere & strDelim & .ItemData(varItem) & _
strDelim & ","
End If
Next
End With
lngLen = Len(strWhere) - 1 'Without trailing comma.
If lngLen > 0 Then
strWhere = "[MyField] IN (" & Left$(strWhere, lngLen) & ")"
End If
DoCmd.OpenReport "MyReport", acViewPreview, , strWhere


Note: If the bound column of the listbox is a Number type field, omit the
line:
strDelim = """"
 
Back
Top