Results 1 to 5 of 5
  1. #1
    jaromluker is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Sep 2013
    Posts
    8

    Sum fields in child records to give a total in parent record


    I have a one-to-many relationship defined between two tables. The parent table is represented on a form with the child table represented in a subform. I have a cost and a discount field in the child table that are shown on the subform. I have an invisible control on the subform with Control Source: =(1-[Discount])*([Cost]). The control name is "AdjustedCost". I would like the sum of all AdjustedCost controls to appear on the main form as a textbox. Is this possible? I've tried referencing queries, I've tried using DSUM, and nothing seems to give anything other than #Error and #Name?.
    Last edited by jaromluker; 09-13-2013 at 04:44 PM.

  2. #2
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    sum(putwhatyouwanttosumhere) - you can put that as a control source on a textbox and use VBA to plant/paste it into any row on the parent for a permanent record. Place it on the header part of the subform though...

  3. #3
    jaromluker is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Sep 2013
    Posts
    8
    [Ignore what I posted here.]
    Last edited by jaromluker; 09-13-2013 at 04:46 PM. Reason: Wrong

  4. #4
    jaromluker is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Sep 2013
    Posts
    8
    This doesn't change anything. You mentioned using VBA. I'm not as familiar with that as I'd like to be. Could you suggest some pseudo-code or something to pass this information to the parent, because right now the best I get is getting the AdjustedCost for the currently selected record on the subform, and not a sum of all the AdjustedCost controls from each of many records in the subform.

  5. #5
    jaromluker is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Sep 2013
    Posts
    8
    Solved the problem with DSUM. A lot of recommendations I've seen for DSUM show the criteria as follows: "[FieldName]=" & <code here>
    I found that "[FieldName]=<code here>" solved the problem. I suppose that's because the data type for the particular field is a string, not a number. If someone out there could verify that for me...

    So I used DSUM("(1-[Discount])*([Cost])","[Orders]","[AccountName]=[Forms]![AccountName].[CurrentAccount]") where I named the TextBox tied to the AccountName field in the parent table CurrentAccount.

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

Similar Threads

  1. Replies: 3
    Last Post: 07-03-2013, 01:20 PM
  2. Replies: 3
    Last Post: 08-09-2012, 01:49 PM
  3. How to make Parent field store sum of child fields
    By Alexandros in forum Database Design
    Replies: 10
    Last Post: 03-19-2012, 10:41 AM
  4. Delete child records with parent record
    By jpkeller55 in forum Access
    Replies: 8
    Last Post: 09-07-2010, 08:52 PM
  5. Parent/Child subform
    By Jerry8989 in forum Forms
    Replies: 1
    Last Post: 09-18-2009, 07:27 AM

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