Afternoon,
I've been browsing through numerous forums and have finally been able to figure out how to query results based on a list box. However, I need to query results off selections in two list boxes. I cannot figure out how to merge the two into the same query. The 2nd list box results always override the first listbox - meaning the 1st ListBox is more or less pointless.
I took the code from the MS Support Site:
Code:
Private Sub Command4_Click()
Dim Q As QueryDef, DB As Database
Dim Criteria As String
Dim ctl As Control
Dim Itm As Variant
' Build a list of the selections.
Set ctl = Me!
[List0]
For Each Itm In ctl.ItemsSelected
If Len(Criteria) = 0 Then
Criteria = Chr(34) & ctl.ItemData(Itm) & Chr(34)
Else
Criteria = Criteria & "," & Chr(34) & ctl.ItemData(Itm) _
& Chr(34)
End If
Next Itm
If Len(Criteria) = 0 Then
Itm = MsgBox("You must select one or more items in the" & _
" list box!", 0, "No Selection Made")
Exit Sub
End If
' Modify the Query.
Set DB = CurrentDb()
Set Q = DB.QueryDefs("qry_IncType")
Q.SQL = "Select * From tbl_FinalCapture Where [Incident Type] In(" & Criteria & _
");"
' Run the query.
DoCmd.OpenQuery "qry_IncType"
End Sub
However, I need to include
[List2] selections into this query.
Any help would be appreciated. I'm a bit of a VBA noob.
Regards,
Travis