Results 1 to 11 of 11
  1. #1
    ezybusy is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2015
    Posts
    119

    Error in syntax

    Can someone please tell me what i am doing wrong here:

    Code:
    Me.LstItemList.RowSourceType = "Table/Query"
    Me.LstItemList.RowSource = ("SELECT ITEM.ItemName AS [ITEM / ARTICLE], FORMAT(Item.ItemPrice, "¢ #,##0.00") AS PRICE, SaleTransDetail.QtyOrdered AS QTE, FORMAT([ItemPrice]*[QtyOrdered], "¢ #,##0.00") AS [COST]" & _
         " FROM SaleTransaction INNER JOIN (ITEM INNER JOIN SaleTransDetail ON ITEM.ItemID_PK = SaleTransDetail.ItemID_FK) ON SaleTransaction.SaleTransID_PK = SaleTransDetail.SaleTransID_FK" & _
         " WHERE SaleTransaction.ClientTableID_FK=" & Me.ClientTableID_FK & _
         " ORDER BY Item.ItemName ")
      Me.LstItemList.Requery
    The code works just fine without the FORMAT function. But once i add it the line become red.
    Am i missing something? Or this is not the right way to use the FORMAT function?

    NB: I am only trying to format the price and the cost fields to match a specific currency format.



    Thanks in advance.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Show us the design of your tables
    SaleTransaction
    Item
    SaleTransDetail

  3. #3
    ezybusy is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2015
    Posts
    119
    @Orange

    here is the design

    Click image for larger version. 

Name:	Capture.PNG 
Views:	14 
Size:	8.7 KB 
ID:	31230

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    I tried simpler formats to see the result

    ?format(12345,"$0000.00")
    $12345.00

    ?format(12345,"$##,000.00")
    $12,345.00

    ?format(12345,"¢ #,##0.00")
    ¢ 12,345.00

    I would include the CurrentSellingPrice or AgreedToPrice in the SaleTransDetail table. If you rely on the ItemPrice from the Item table, you'll find that historic values (Invoices/Transactions) will have errors. If you change the ItemPrice in the Item table, which you will do at some point, then your old SaleTransDetail records will use the latest ItemPrice which isn't the Price of that Item when the original Item was sold.

  5. #5
    ezybusy is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2015
    Posts
    119
    @Orange

    Still the same error for the FORMAT function.

    Regarding the ItemPrice, i have setup an arching table where all details are posted when the user clicks on a button called "END TRANSACTION". And most queries are based on that archiving table. so no worries for that.


  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  7. #7
    ezybusy is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2015
    Posts
    119
    here.
    Click image for larger version. 

Name:	Capture.PNG 
Views:	14 
Size:	5.8 KB 
ID:	31231

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  9. #9
    ezybusy is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2015
    Posts
    119
    yeah you right.

    But what of the calculated field in the the query ([ItemPrice]*[QtyOrdered]) ?

  10. #10
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,941
    since you are building a string, your format function needs to use single quotes

    FORMAT(Item.ItemPrice, '¢ #,##0.00') AS PRICE

    Also not sure about using the opening/closing brackets for the entire string

    Me.LstItemList.RowSource = ("SELECT.....

  11. #11
    ezybusy is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2015
    Posts
    119
    @Ajax

    It works. Thank you a bunch for your help. NB: the opening/closing brackets have no problem at all on my side.

    @Orange

    Thank you for the consideration.

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

Similar Threads

  1. Replies: 2
    Last Post: 01-04-2016, 09:40 AM
  2. Replies: 11
    Last Post: 05-01-2014, 11:56 AM
  3. Replies: 3
    Last Post: 01-23-2014, 07:49 AM
  4. Replies: 6
    Last Post: 05-30-2012, 12:32 PM
  5. Incomplete Syntax Clause (syntax error)
    By ajetrumpet in forum Programming
    Replies: 4
    Last Post: 09-11-2010, 10:47 AM

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