Article ID: 135546
Article Last Modified on 1/19/2007
Name: List0 Row Source: Customers Column Count: 2 Column Widths: .5";2" Multi Select: Extended Width: 2.5"
Option Compare Database
Option Explicit
Private Sub Command2_Click()
Dim Criteria As String
Dim i As Variant
' Build criteria string from selected items in list box.
Criteria = ""
For Each i In Me![List0].ItemsSelected
If Criteria <> "" Then
Criteria = Criteria & " OR "
End If
Criteria = Criteria & "[CustomerId]='" _
& Me![List0].ItemData(i) & "'"
Next i
' Filter the form using selected items in the list box.
Me.Filter = Criteria
Me.FilterOn = True
End Sub
Name: List0 RowSource: Customers ColumnCount: 2 ColumnWidths: .5";2" Multiselect: Extended Width: 2.5"
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("MultiSelect Criteria Example")
Q.SQL = "Select * From Orders Where [CustomerID] In(" & Criteria & _
");"
Q.Close
' Run the query.
DoCmd.OpenQuery "MultiSelect Criteria Example"
End Sub
Additional query words: listbox inf
Keywords: kbhowto kbusage KB135546