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
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