Spidey3721 said:
I am trying to limit a report to only include items that the user has
selected in a multiselect list box. Right now I am setting the
criteria of the listbox control source to the following.
Forms![NameofForm]![NameofListBox].ItemsSelected
I presume you mean you're setting the criteria of the report's
recordsource -- but that still won't work. The standard and most
efficient way of doing this is to use code to loop through the list
box's ItemsSelected collection and build up a criteria string, which you
then specify as the WhereCondition argument on the DoCmd.OpenReport
statement that opens the report. Code looks something like this:
'----- start of example code ("air code") -----
Private Sub cmdPreviewReport_Click()
Dim strCriteria As String
Dim varItem As Variant
With Me.lstMyListBox
For Each varItem In .ItemsSelected
strCriteria = strCriteria & ", " & .ItemData(varItem)
Next varItem
End With
If Len(strCriteria) = 0 Then
MsgBox "No items selected for the report!"
Else
' drop leading ", " and add rest of condition
strCriteria = "KeyField In (" & Mid$(strCriteria, 3) & ")"
' display the report
DoCmd.OpenReport "rptMyReport", acPreview, _
WhereCondition:=strCriteria
End If
End Sub
'----- end of example code ("air code") -----
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)