Results 1 to 7 of 7
  1. #1
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727

    adding fields in query

    all, using access 2003. have table contains number fields. I am using a query in a subform. I want to add the number fields to place them on a field called total charges. please help. this is what i am placing in the query



    Code:
     
    TOTALCHARGES: DSum([NUM_TRANSCHG],[NUM_FUELSURCHG],[NUM_ACCESCHG],[NUM_OTHERCHG])
    its returning a error about wrong # of arguments.
    thanks

  2. #2
    Rainlover's Avatar
    Rainlover is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2009
    Location
    Queensland Australia
    Posts
    691
    It is not "Best Practise" to store calculated values. The better method is to calculate when you need the value.

    Sum is not what I think you want because it returns the Sum of all the values in one field.

    You simply need to use +

  3. #3
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    ok. i need to use it on a subform. in the query using +; it works but only if all the fields have something in them How can I correct this using the calculated field on a subform that allows any of the fields to be empty. thanks

  4. #4
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    Access does not know what to do in a calculation if a field is empty. You need to tell it what to do. This is where the NZ function applies. Here is an explanation of the NZ function and how to employ it.

    http://www.techonthenet.com/access/f...dvanced/nz.php

    So if you had a field named, Output and you wished to add it to a field named Receipts you would use the following expression
    NZ(Output,0) + NZ(Receipts,0)

    This tells Access that if there is nothing in either of those fields, use a zero. Now Access can do a calculation

  5. #5
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    thanks! this work. can i do the same in vba to use it on a subform since its not good practice to store calculated fields?

  6. #6
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    I got it. But I am having a problem with making the field 2 decimals. I have the field properties set at 2 but it still appears 4 instead of 4.00. any ideas

  7. #7
    Rainlover's Avatar
    Rainlover is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2009
    Location
    Queensland Australia
    Posts
    691
    Try formating the field as Decimal. (Not tested)

    Do this on the Form.

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

Similar Threads

  1. Adding fields together in report
    By GraemeG in forum Reports
    Replies: 2
    Last Post: 06-04-2011, 09:20 AM
  2. Adding Fields
    By jlclark4 in forum Queries
    Replies: 3
    Last Post: 04-08-2011, 03:20 PM
  3. Adding 2 fields together
    By Craig Spencer in forum Access
    Replies: 2
    Last Post: 04-08-2011, 02:10 PM
  4. Adding of Fields in Different records
    By pcliaros in forum Queries
    Replies: 1
    Last Post: 03-17-2010, 02:31 AM
  5. Replies: 4
    Last Post: 09-21-2009, 01:51 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