Combining two Multiselect List Boxes

R

Radar

I modified the code to work with one of my multiselect list boxes.
How do I get this code to use two listboxes.
I have another a list box call lstSize' to coincide with field
Store.Size in the same qry


' 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("qryTabbox")
' Loop through the selected items in the list box and build a text
string
For Each varItem In Me!lstRegions.ItemsSelected
strCriteria = strCriteria & ",'" &
Me!lstRegions.ItemData(varItem) & "'"
Next varItem
' Check that user selected something

If Len(strCriteria) = 0 Then
MsgBox "You did not select anything from the list" _
, vbExclamation, "Nothing to find!"
Exit Sub
End If
' Remove the leading comma from the string
strCriteria = Right(strCriteria, Len(strCriteria) - 1)
' Build the new SQL statement incorporating the string
strSQL = "SELECT * FROM Store " & _
"WHERE Store.Daysout IN(" & strCriteria & ");"

' Apply the new SQL statement to the query
qdf.SQL = strSQL
' Open the query
DoCmd.OpenQuery "qrytabbox"
' Empty the memory
Set db = Nothing
Set qdf = Nothing
 
D

Douglas J Steele

You have to create another loop to concatenate whatever's selected from
lstSize into another string (say strCriteria2).

You'd then build your SQL string like

strSQL = "SELECT * FROM Store " & _
"WHERE Store.Daysout IN(" & strCriteria & ") " & _
"AND Store.Size IN(" & strCriteria2 & ")"

(FWIW, there's no need to include a terminating semi-colon)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top