Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Aztecfan63 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2020
    Location
    Chula Vista, CA
    Posts
    26

    should i use a select query to find the Sum of a field?


    I would like to show the total (sum) of cost field in a Report. it should be simple but I am missing something.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Expression in textbox in report footer: =Sum(fieldname)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Aztecfan63 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2020
    Location
    Chula Vista, CA
    Posts
    26
    when I created a Textbox in the footer of my report and entered "=Sum(Original Cost)" I received the message "The expression you entered contains invalid syntax."

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    No quotes.
    Attached Thumbnails Attached Thumbnails Sum.png  
    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

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Also, due to the inadvisable space you'd need to bracket the field name:

    =Sum([Original Cost])
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Aztecfan63 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2020
    Location
    Chula Vista, CA
    Posts
    26
    I went back to my tools table and renamed
    Code:
    Original Cost
    to
    Code:
    Cost
    .now I simply get #Error. also I tried assigning a name (TotCost) in front of
    Code:
    =sum(Cost)
    that gives Invalid Source code.
    Last edited by Aztecfan63; 08-05-2024 at 02:24 PM. Reason: miss spelling

  7. #7
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    566
    You are leaving out the square brackets. That's how Access knows you are referring to a column in a table and not a custom function.

  8. #8
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Put it back to Original Cost but as shown in post 5. Then from here on, no spaces or special characters in ANY object name. Underscore is allowed but I almost never use it in favour of Camel Case.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    That's how Access knows you are referring to a column in a table
    Brackets would be required around any object name that contains spaces, subject to naming rules AFAIK. That includes control names which Original Cost probably is, and would have to be an unbound control in order to contain an expression, hence it can't be a field name in this case.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    566
    One of the reasons to rename the controls on your forms... so they have some kind of prefix... makes it obvious that it's a form control! =)

  11. #11
    Aztecfan63 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2020
    Location
    Chula Vista, CA
    Posts
    26
    In my Tools table I went back to Original Cost. now in the Report textbox it looks like = Sum([Original Cost]). This causes: The expression you entered contains invalid syntax

  12. #12
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    566
    Is [Original Cost] in the source that the report is based on?

    Can you post the source? (if it's a table, is [Original Cost] a column in that table?)

  13. #13
    Aztecfan63 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2020
    Location
    Chula Vista, CA
    Posts
    26
    1. yes, Original Cost is a field in my Tools Inventory table.
    2. I did a Compact & Repair then Zip my database How do I send (post the source ) to you?

  14. #14
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    566
    Click the Go Advanced button below the message text box and then you can upload your file.

  15. #15
    Aztecfan63 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2020
    Location
    Chula Vista, CA
    Posts
    26

    database7.zip

    Database7.zipThis is my Tools Inventory.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 32
    Last Post: 04-20-2022, 09:44 AM
  2. Replies: 3
    Last Post: 02-14-2018, 07:18 PM
  3. Replies: 3
    Last Post: 02-07-2016, 10:49 AM
  4. Replies: 1
    Last Post: 12-20-2013, 05:14 PM
  5. query to find the highest value in a field
    By jhjarvie in forum Queries
    Replies: 0
    Last Post: 09-02-2008, 02:27 PM

Tags for this Thread

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