What's wrong with the following code

P

Paul

I have the following code when execute returns with an error saying "Syntax
error (missing operator) in query expression '(((Orders.OrderID) = IN
(465,477)) And ((Orders.Status)=1))'. Thanks.


Private Sub Command28_Click()
Dim frm As Form, ctl As Control
Dim varItem As Variant
Dim stDocName As String
Dim stLinkCriteria As String
Dim stWhat As String
Dim stCriteria As String
Dim loqd As QueryDef
Dim stSQL As String
On Error GoTo Err_Command28_Click

stWhat = "": stCriteria = ","
Set frm = [Forms]![Frm_Pull Sheet]
Set ctl = frm!lstStorePO
stDocName = "Rpt_Store PO Pull Sheet"
For Each varItem In ctl.ItemsSelected
stWhat = stWhat & ctl.ItemData(varItem)
stWhat = stWhat & stCriteria
Next varItem
stLinkCriteria = CStr(Left$(stWhat, Len(stWhat) - Len(stCriteria)))

Set loqd = CurrentDb.QueryDefs("Qry_Store PO")
stSQL = "SELECT Orders.OrderID, Orders.PurchaseOrder, Orders.Status " &
_
"FROM Orders " & _
"WHERE (((Orders.OrderID) = IN (" & stLinkCriteria & ")) And
((Orders.Status) = 1)) " & _
"ORDER BY Orders.PurchaseOrder;"
loqd.SQL = stSQL
loqd.Close
Debug.Print loqd.SQL
DoCmd.OpenReport stDocName, acPreview


Exit_Command28_Click:
Exit Sub

Err_Command28_Click:
MsgBox Err.Description
Resume Exit_Command28_Click

End Sub
 
J

JohnFol

The bit that says
(Orders.OrderID) = IN (465,477)
Should be
(Orders.OrderID) IN (465,477)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top