Try this:
Dim ctl As Control
Dim varItem As Variant
Dim strSql As String
Set ctl = Me![lstSummaries]
strSql = "[SummaryID] IN ("
'Assume [SummaryID] is the bound field in listbox
'enumerate selected items and
'concatenate to strSQL
For Each varItem In ctl.ItemsSelected
strSql = strSql & ctl.ItemData(varItem) & ", "
Next varItem
'If no category is selected, make it null in the criteria.
If strSql = "[CategoryID] IN (" Then
DoCmd.OpenReport stDocName, acPreview
Else
strSql = Left$(strSql, Len(strSql) - 2) & ")"
DoCmd.OpenReport "Summary Report", acPreview, , strSql
End If
Tru said:
Allen can you tell me what is wrong with code.
Dim Criteria As String
Dim i As Variant
' Build criteria string from selected items in list box.
Criteria = ""
For Each i In Me![lstSummaries].ItemsSelected
If Criteria <> "" Then
Criteria = Criteria & " OR "
End If
Criteria = Criteria & "[SummaryID]='" & Me![lstSummaries].ItemData(i)
& "'"
'Open Report
DoCmd.OpenReport "Summary Report", acPreview, , "[SummaryID]=Criteria
Next i
:
Loop through the ItemsSelected collection of the list box, using OpenReport
for each one.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
How do I use a multi-select Listbox to select multiple reports to print?
I
know this is a tricky procedure if you can help I appreciate it.