Question : SELECT query based on selected Listbox values

I have the following query under the load event for a form which limits the records displayed to those associated with the current user:

Me.RecordSource = "SELECT * FROM tblData WHERE UserID=forms!frmLogon!txtUserID"
Me.Refresh

I now want to have a multi-select listbox that allows the user to select one or more UserID's from the list and return all
records associated with those UserID's.    Can someone show me how to modify the SELECT query about to accomplish this?    Presume my listbox name is lstUserID and UserID is a field in my table.  

Answer : SELECT query based on selected Listbox values

The work does not end at just generating the SQL statement...you have to put it to use!  Looks like you have a good start though.  Try this out:

Private Sub cmdQuery_Click()

Dim x As Variant

sList = ""
For Each x In lstEmployees.ItemsSelected
    sList = sList & lstEmployees.ItemData(x) & ","
Next
sList = Left(sList, Len(sList) - 1)

sSQL = "SELECT * FROM tblData WHERE Employee IN (" & sList & ")"

''''''''''''''''''''''''''''''
' The next two lines are additions
Me.RecordSource = sSQL
Me.Requery

End Sub
Random Solutions  
 
programming4us programming4us