Search code examples
vbams-access

Setting this filter gives 'Syntax error in query expression'


This code in a button OnClick event

  With frm
     .Filter = strWhere  ' Error here
     .FilterOn = True
     .OrderBy = strOrderBy
     .OrderByOn = True
  End With

where strWhere is

 "([Orders].[ID] in (SELECT [Job Orders].OrderFID     
  FROM [Job Orders]     
  WHERE (([Job Orders].BillJobFID)=1324)));"

gives 'Syntax error in query expression', but if I take the same where clause and create a select statement, it works fine.

SELECT * FROM Orders WHERE    
([Orders].[ID] in (SELECT [Job Orders].OrderFID    
FROM [Job Orders]     
WHERE (([Job Orders].BillJobFID)=1324)));"

I don't see what I'm missing.


Solution

  • The reason I posted was because I was at a dead end about how to debug this.
    Turns out that my problem was that I was comparing apples and oranges.

    It works when I add the filter to "Select * from Orders".
    But that isn't what the form does.

    Once I added the filter to the query used as the recordset on the form, the problem immediately became apparent.