Unanswered: open report based on listbox selection(s)
hello. i have a report that i am opening via a command button in a form. also in this form is a multiple selection listbox with the 50 states. i want for the report to open displaying only the records for the selected states in the listbox. how can i do this?
Here's something I made recently. You can use it to make a string to put as the filter. To call it, you can go GetSelectedItems(listbox, "State IN('", "',", "')"), which would give you STATE IN('NY', 'MA').
Public Function GetSelectedItems(lst As ListBox, Optional strPrefix As String = "", Optional strDelimiter As String = "", Optional strPostfix As String = "") As String
'returns a string containing all the items selected in the listbox
Dim varCount As Variant
Dim str As String
str = strPrefix
'get items in listbox
For Each varCount In lst.ItemsSelected
str = str & lst.ItemData(varCount) & strDelimiter
'get rid of last delimiter
If strDelimiter <> "" Then
str = Left(str, Len(str) - Len(strDelimiter))