Hi KF,
here is some code you can use to do that.
Private Function BuildWhereCondition(strControl As String) As String
'Set up the WhereCondition Argument for the query
Dim varItem As Variant
Dim strWhere As String
Dim ctl As Control
Set ctl = Me.Controls(strControl)
Select Case ctl.ItemsSelected.Count
Case 0 'Include All
strWhere = ""
Case 1 'Only One Selected
strWhere = "= '" & _
ctl.ItemData(ctl.ItemsSelected(0)) & "'"
Case Else 'Multiple Selection
strWhere = " IN ("
With ctl
For Each varItem In .ItemsSelected
strWhere = strWhere & "'" & .ItemData(varItem) & "', "
Next varItem
End With
strWhere = Left(strWhere, Len(strWhere) - 2) & ")"
End Select
End Sub
Private Sub MyQuery()
Dim strSQL as String
strSQL = "SELECT yadda, yadda, yadda " _
& "FROM yadda " & BuildWhereCondition(strControl As String)
End Sub
Notes:
replace
BuildWhereCondition(strControl As String)
with
BuildWhereCondition("NameOfTheListBox")
use strSQL as the query.
Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
[quoted text clipped - 6 lines]