I have a Listbox with Extended selection enable and called List4
I also have a Query called UPLOAD Query and Table called UPLOAD
I have a code that will enter in a SQL statement into my UPLOAD Query based on the varItems selected in my List Box: List4
When I run this code the query pops up with nothing.... I noticed that the criteria in the query is referencing numbers like ex. IN('7','6') etc instead of the actual data of the items selected form the List Box...? ex IN("Specific Media","KSL")...
Here is my code:
And this is the SQL statement that appears in the UPLOAD Query after I run the code:
Can anyone spot where my problem lies??
Any suggestions would be greatly appreciated
I also have a Query called UPLOAD Query and Table called UPLOAD
I have a code that will enter in a SQL statement into my UPLOAD Query based on the varItems selected in my List Box: List4
When I run this code the query pops up with nothing.... I noticed that the criteria in the query is referencing numbers like ex. IN('7','6') etc instead of the actual data of the items selected form the List Box...? ex IN("Specific Media","KSL")...
Here is my code:
Code:
Option Compare Database
Private Sub Command8_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("UPLOAD Query")
For Each varItem In Me!List4.ItemsSelected
strCriteria = strCriteria & ",'" & Me!List4.ItemData(varItem) & "'"
Next varItem
If Len(strCriteria) = 0 Then
MsgBox "You did not select anything from the list", vbExclamation, "Nothing to find!"
Exit Sub
End If
strCriteria = Right(strCriteria, Len(strCriteria) - 1)
strSQL = "SELECT * FROM UPLOAD " & "WHERE UPLOAD.[Payable To:] IN(" & strCriteria & ");"
qdf.SQL = strSQL
DoCmd.OpenQuery "UPLOAD Query"
End Sub
And this is the SQL statement that appears in the UPLOAD Query after I run the code:
Code:
SELECT *
FROM UPLOAD
WHERE UPLOAD.[Payable To:] IN('7','6');
Can anyone spot where my problem lies??
Any suggestions would be greatly appreciated