superfly5203
Registered User.
- Local time
- Yesterday, 22:03
- Joined
- Apr 5, 2016
- Messages
- 43
I'll start off by saying, I have searched this form and all over google and I have seen tons of these examples, but I can't get any of them to work. I saw one in this thread from a few days ago and a couple months ago, but no matter how much I alter the code I don't get the correct outcome.
So, I have an unbound form that has one listbox, "contractlist" that has three different contract names in it. The point of this query will be to search all records for as many of the contracts the user has selected. Right now i'm using this code, and it sort of works:
Right now there are two issues. One is after I make my selections on my form and hit my command button, I get a pop up to enter a parameter value for the Contract I selected in my list box. If I did two selections, I'll get two pop ups. If i type in my contract title again in the pop up, the query runs correctly and returns all the records associated with those contracts. However, it returns all the fields in the table I'm querying, and it keeps deleting my query settings.
I would like to add a couple more list boxes with the same multi select option to this query, once I can get one working. Also, I have no idea what about 90% of this code means, but I keep learning one issue at a time.
Thanks for any help!
So, I have an unbound form that has one listbox, "contractlist" that has three different contract names in it. The point of this query will be to search all records for as many of the contracts the user has selected. Right now i'm using this code, and it sort of works:
Code:
Private Sub cmdok_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL As String
Set db = CurrentDb()
Set qdf = db.QueryDefs("Query1")
For Each varItem In Me!contractlist.ItemsSelected
strCriteria = strCriteria & "," & Me!contractlist.ItemData(varItem) & ""
Next varItem
If Len(strCriteria) = 0 Then
MsgBox "You did not select anything." _
, vbExclamation, "Nothing to find!"
Exit Sub
End If
strCriteria = Right(strCriteria, Len(strCriteria) - 1)
strSQL = "SELECT* FROM tblChangeBasic " & _
"WHERE tblChangeBasic.contract IN(" & strCriteria & ");"
qdf.SQL = strSQL
DoCmd.OpenQuery "Query1"
Set db = Nothing
Set qdf = Nothing
End Sub
Right now there are two issues. One is after I make my selections on my form and hit my command button, I get a pop up to enter a parameter value for the Contract I selected in my list box. If I did two selections, I'll get two pop ups. If i type in my contract title again in the pop up, the query runs correctly and returns all the records associated with those contracts. However, it returns all the fields in the table I'm querying, and it keeps deleting my query settings.
I would like to add a couple more list boxes with the same multi select option to this query, once I can get one working. Also, I have no idea what about 90% of this code means, but I keep learning one issue at a time.
Thanks for any help!