hgus393
Registered User.
- Local time
- Today, 07:33
- Joined
- Jan 27, 2009
- Messages
- 83
Hi all!
I wonder if there is someone who knows how I can pass several listbox multiselects from a form to a query. I have some code that already passes one listbox with multiselects...can this code be adjusted to fit several listbox multiselects?
Thankful for any help

I wonder if there is someone who knows how I can pass several listbox multiselects from a form to a query. I have some code that already passes one listbox with multiselects...can this code be adjusted to fit several listbox multiselects?
Code:
'Declare variables
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL As String
' Get the database and stored query
Set db = CurrentDb()
Set qdf = db.QueryDefs("QueryFindWithDates>Q")
' Loop through the selected items in the list box and build a text string
If Me!InstrList.ItemsSelected.Count > 0 Then
For Each varItem In Me!InstrList.ItemsSelected
strCriteria = strCriteria & Chr(34) _
& Me!InstrList.ItemData(varItem) & Chr(34) Or "
Next varItem
strCriteria = Left(strCriteria, Len(strCriteria) - 3)
End If
'Build the new SQL statement incorporating the string
strSQL = "SELECT * FROM QueryFindWithDatesQ " & _
"WHERE " & strCriteria & ";"
' Apply the new SQL statement to the query
qdf.sql = strSQL
' Open the query
DoCmd.OpenQuery "QueryFindWithDates>Q"
' Empty the memory
Set db = Nothing
Set qdf = Nothing
End Sub