Sometimes, a bit of code can paint a thousand words. From this at least I can follow where you need a little more direction.
DoCmd.OpenReport has a parameter that you haven't used, called
WhereCondition (not to be confused with
FilterName). This is the fourth parameter. Parameters can also be passed by name if preferred :
- Call DoCmd.OpenReport(ReportName:=stDocName, _
-
View:=acPreview, _
-
WhereCondition:=strWhere)
Before the call is made you need to translate the various items in your ListBox, using
ItemsSelected (in a loop) to produce a string formatted like a SQL WHERE clause but without the "WHERE " part.
- Dim strWhere As String
-
Dim varX As Variant
-
-
With Me.List0
-
For Each varX In .ItemsSelected
-
strWhere = strWhere & "," & .ItemData(varX)
-
Next varX
-
strWhere = "[SurveyCode] In(" & Mid(strWhere,2) & ")"
-
Call DoCmd.OpenReport(ReportName:=stDocName, _
-
View:=acPreview, _
-
WhereCondition:=strWhere)
-
End With
From your posted SQL, your problem is that
ItemsSelected is not a string value so would be entirely unusable in SQL directly. My earlier code illustrates how a SQL string should be set up as it works on very similar lines. Also, as the SQL that the report is built on is encapsulated within the report object itself, any change to the SQL would have to be entered as the property
.RecordSource of the report.