K
Kelly S
Can someone help me with the proper code in order to use multiple multiselect
listboxes to limit records in a report. I want to have two listboxes, one
with contractor types and one with regions. I want to pick options from each
listbox and limit my report based on both.
I have used the following code from the
http://www.mvps.org/access/forms/frm0007.htm website and can run my report
using one multiselect listbox, but I can't seem to get the syntax down for
two multiselect listboxes.
Also, do I need to use separate forms for the two listboxes or can I put
them both on one form?
************ Code Start **********
Private Sub btnTestQuery_Click()
Dim vItm As Variant
Dim stWhat As String
Dim stCriteria As String
Dim stSQL As String
Dim loqd As QueryDef
stWhat = "": stCriteria = ","
For Each vItm In Me!mslbxTest.ItemsSelected
stWhat = stWhat & Me!mslbxTest.ItemData(vItm)
stWhat = stWhat & stCriteria
Next vItm
Me!txtCriteria = CStr(left$(stWhat, Len(stWhat) - Len(stCriteria)))
Set loqd = CurrentDb.QueryDefs("qryMultiSelTest")
stSQL = "SELECT EmployeeID, LastName, FirstName, TitleOfCourtesy, "
stSQL = stSQL & "Title FROM Employees WHERE EmployeeID"
stSQL = stSQL & " IN (" & Me!txtCriteria & ")"
loqd.SQL = stSQL
loqd.Close
DoCmd.OpenQuery "qryMultiSelTest"
End Sub
'************ Code End **********
Thank you so much for any help,
Kelly S
listboxes to limit records in a report. I want to have two listboxes, one
with contractor types and one with regions. I want to pick options from each
listbox and limit my report based on both.
I have used the following code from the
http://www.mvps.org/access/forms/frm0007.htm website and can run my report
using one multiselect listbox, but I can't seem to get the syntax down for
two multiselect listboxes.
Also, do I need to use separate forms for the two listboxes or can I put
them both on one form?
************ Code Start **********
Private Sub btnTestQuery_Click()
Dim vItm As Variant
Dim stWhat As String
Dim stCriteria As String
Dim stSQL As String
Dim loqd As QueryDef
stWhat = "": stCriteria = ","
For Each vItm In Me!mslbxTest.ItemsSelected
stWhat = stWhat & Me!mslbxTest.ItemData(vItm)
stWhat = stWhat & stCriteria
Next vItm
Me!txtCriteria = CStr(left$(stWhat, Len(stWhat) - Len(stCriteria)))
Set loqd = CurrentDb.QueryDefs("qryMultiSelTest")
stSQL = "SELECT EmployeeID, LastName, FirstName, TitleOfCourtesy, "
stSQL = stSQL & "Title FROM Employees WHERE EmployeeID"
stSQL = stSQL & " IN (" & Me!txtCriteria & ")"
loqd.SQL = stSQL
loqd.Close
DoCmd.OpenQuery "qryMultiSelTest"
End Sub
'************ Code End **********
Thank you so much for any help,
Kelly S