I have an unbound form which uses a multiselect listbox to collect criteria data. The report is bound to a query and I am trying to pass the listbox .ItemsSelected as the criteria for the query behind the report.
I have the following code on the On_click event of the preview button:
Private Sub cmdPreview_Click()
On Error GoTo Err_cmdPreview_Click
Dim stDocName As String
Dim varItem As Variant
Dim strCriteria As String
strType = ""
For Each varItem In Me!List2.ItemsSelected
strCriteria = Me!List2.Column(0, varItem)
strType = strType & "," & strCriteria
Where do you instantiate the strType variable? How do you make the global assignment of rtnstrType? Check those things 1st. As an aside, look carefully at you selection criteria. You have a leading comma there that I don't see code to remove ...
You state it doesn't work ... WHAT doesn't work? The report? What is it doing/not doing that is incorrect?
Thank you, after I read your first reply I took out the leading , and it still was not filtering correctly. So, I took out the function and the global string. Instead I made a field on my form that was not visible and had the it update after each selection of the list. Then I used the form field as the criteria for my report. It seems to work just fine.
Thanks I've tried it with and without the quotes and neither seems to work. If i have the quotes none of the selections work. without the quotes I can get the selection to work but only when there is a single selection.