Results 1 to 3 of 3
  1. #1
    TOPSie is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2021
    Posts
    108

    syntax error missing operator in query expression

    My apologies for posting this it is probably trivial but I just can't see what is wrong here:



    I have a form with Record Source with the following clause:
    Code:
    ORDER BY tblSalesTransactions.Date, tblSalesTransactions.SalesTransactionNumber, tblSalesTransactions.AmountGross;
    The user want one particular account to sort differently. So I have written a function:
    Code:
    Public Function IsSuspenceAccount(ID As Long) As Boolean
    If ID = 2840 Then
        IsSuspenceAccount = True
    Else
        IsSuspenceAccount = False
    End If
    End Function
    and changed the ORDER BY clause

    Code:
    ORDER BY IIf(IsSuspenceAccount([tblSalesTransactions.CustomerID])=TRUE, [tblSalesTransactions.Date] DESC, [tblSalesTransactions.Date]), 
    tblSalesTransactions.SalesTransactionNumber, tblSalesTransactions.AmountGross;
    But it fails "syntax error" quoting the IIf statement.
    Probably missing a comma or bracket = but I have tried various combinations.
    So wondering is you can have an IIF in the ORDER BY Clause at all????

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    I think you are going to have to build that SQL string using that logic first, then run that SQL.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    TOPSie is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2021
    Posts
    108
    Thank you. Yes updating the form RecordSource in code did the trick :-)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Syntax Error (missing operator) in query expression
    By johndoe123 in forum Programming
    Replies: 2
    Last Post: 05-13-2019, 07:56 PM
  2. Replies: 3
    Last Post: 11-07-2017, 06:26 PM
  3. Replies: 5
    Last Post: 10-25-2017, 01:47 PM
  4. Replies: 2
    Last Post: 02-17-2014, 10:27 AM
  5. Replies: 9
    Last Post: 01-22-2013, 04:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums