Multi Select List Box --> Query

Thanks very much dcx693. That has worked a treat!

Thanks for your suggestions as well Neil.
 
This code is also work fine.

I have 2 Listboxes in my form name frmMyForm.
The listboxes named list0 and list2.
I have a textbox named text4.
And I put this code to a command box event on click.



Private Sub Command3_Click()
Dim varItem As String
Dim i As Variant
' Build criteria string from selected items in list box.
varItem = ""
j = 0
For Each i In Me![List0].ItemsSelected
If varItem <> "" Then
varItem = varItem & " , "
End If
If j = 1 Then
varItem = varItem _
& Me![List0].ItemData(i) & ""
Else
varItem = varItem _
& Me![List0].ItemData(i) & ""
j = 1
End If
Next i
' Filter the form using selected items in the list box.
Text4 = varItem
List2.RowSource = "SELECT * FROM ReqItem WHERE [ID] In(" & varItem & ");"
End Sub
 
Oops, just this code.

Private Sub Command3_Click()
Dim varItem As String
Dim i As Variant
' Build criteria string from selected items in list box.
varItem = ""
For Each i In Me![List0].ItemsSelected
If varItem <> "" Then
varItem = varItem & " , "
End If
varItem = varItem & Me![List0].ItemData(i) & ""
Next i
' Filter the form using selected items in the list box.
Text4 = varItem
List2.RowSource = "SELECT * FROM ReqItem WHERE [ID] In(" & varItem & ");"
End Sub
 

Users who are viewing this thread

Back
Top Bottom