Ok. I created a little demo for you with my data:
1) create a dummy query in the query view. Mine is qryDummy. I just did a select * on a table. Doesn't matter which table since it is just a query to hold our results later.
2) create a form with two objects on it. A list box. I called mine lstMyList. Make sure you set the multi select to Extended. This will allow the user to do multiple selection the same as any windows list (using cntl or shift)
I placed 5 different values in the Row Source. My Value list looks like this:
"TRNSFR";"DIRDEP";"DIRMED";"SALARY";"DIRDAY"
You will have to choose your own value list.
Make sure the Row Source Type is value list.
Set up a command button. Mine is called cmdList.
3) While your form is in design mode press the code button and paste this code:
Code:
Private Sub cmdList_Click()
Dim strSQL As String
Dim strWhere As String
Dim varItem As Variant
Dim qry As DAO.QueryDef
strWhere = ""
strSQL = "SELECT * FROM All_Firms "
If Me.lstMyList.ItemsSelected.Count > 0 Then
For Each varItem In Me.lstMyList.ItemsSelected
If Len(strWhere) = 0 Then
strWhere = "WHERE "
Else
strWhere = strWhere & "OR "
End If
strWhere = strWhere & "transaction_type like " & Chr(34) & Me.lstMyList.Column(0, varItem) & "*" & Chr(34) & " "
Next varItem
End If
Set qry = CurrentDb.QueryDefs("qryDummy")
qry.SQL = strSQL & strWhere
qry.Close
End Sub
4) change this line:
strSQL = "SELECT * FROM All_Firms " to select from your table
5) change this line:
strWhere = strWhere & "transaction_type like " & Chr(34) & Me.lstMyList.Column(0, varItem) & "*" & Chr(34) & " "
to start with your field name instead of transaction_type.
6) run the form. select whatever you want and then click the button. What happens then is that the qryDummy that we set up will now display the results of your qruery. You can now use that query to create reports, forms, anything that you would use any other query for. Have fun.
PS. you do not have to type the values into the listbox. You can attach the listbox to a table and have them do selection based on a lookup table.