D
djf44
I found this code in a text book that works for selecting multiple items in a
list box. I can't get the bottom part to work, the part that shows how to
open the query once the parameters have been estblished. The book says to use
CreateQueryDef to open the query. My parameters are getting in correctly, but
I can't get the query to open. Has any one does this before?
Dim varItem As Variant
Dim strInClause As String
If Me!lstCities.ItemsSelected.Count = 0 Then
MsgBox("Please select at least one city.")
Else
strInClause = "[city] IN("
For Each varItem In Me!lstCities.ItemsSelected
strInClause = strInClause & """" & _
Me!lstCities.Column(0,varItem) & """" & ", "
Next varItem
'Remove the trailing comma and space from the last item
strInClause=left(strInClause,len(strInClause)-2) & ")"
End If
Dim qdf As QueryDef
Set qdf = CurrentDb.CreateQueryDef("qrySales", _
"Select * From tblSales Where " & strInClause & ";")
DoCmd.OpenQuery "qrySales"
list box. I can't get the bottom part to work, the part that shows how to
open the query once the parameters have been estblished. The book says to use
CreateQueryDef to open the query. My parameters are getting in correctly, but
I can't get the query to open. Has any one does this before?
Dim varItem As Variant
Dim strInClause As String
If Me!lstCities.ItemsSelected.Count = 0 Then
MsgBox("Please select at least one city.")
Else
strInClause = "[city] IN("
For Each varItem In Me!lstCities.ItemsSelected
strInClause = strInClause & """" & _
Me!lstCities.Column(0,varItem) & """" & ", "
Next varItem
'Remove the trailing comma and space from the last item
strInClause=left(strInClause,len(strInClause)-2) & ")"
End If
Dim qdf As QueryDef
Set qdf = CurrentDb.CreateQueryDef("qrySales", _
"Select * From tblSales Where " & strInClause & ";")
DoCmd.OpenQuery "qrySales"