Results 1 to 5 of 5
  1. #1
    randomaccess is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Jun 2011
    Posts
    2

    Dsum calculation is only picking up a single record

    Hi,



    I have a form embedded within my current form that allows multiple records and uses the table DCPOut. Each record has a qty and I am trying to get a total of the values for each record to appear in the Totals field of the current form (Me.totals). The current form has a field with an ID (Me.ID), this ID is also assigned to each record on tblDCPOut so where there are multiple records, they will share the same ID although they are of course assigned primary keys using another field in the DB.


    Dim totalQty As Long
    totalQty = DSum("qty", "tblDCPOut", "ID=" & Me.ID)
    Me.totals = totalQty

    In the case of the current ID there are 2 records on tblDCPOut but only 1 is being picked up and I cannot see why this is.

    Please excuse my novice questions!

    Any help is appreciated



  2. #2
    evander is offline Competent Performer
    Windows 7 Access 2003
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    206
    Can you create a GROUP BY query whose table source is tblDCPOut? Maybe it can give you a clue.

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Hi

    This is usually done like this:

    Create a new field in the footer of the subform. I would name it "txtQtyTotal". Set the Control Source property of the new field to "=Sum([Qty])" without the quotes.

    The textbox on your Main/Parent form that is to show the total needs to have its' Control Source property to somthing like "=YourSubFormName.Form!txtQtyTotal" without the quotes where YourSubFormName is the name of your subform.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    randomaccess is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Jun 2011
    Posts
    2
    Thanks Bob Fitz, I think I'm partially there.

    I now have a Sum of the Qty for both records in my Sub form.

    My Totals field needs to update the DB using the Control Source so I am trying to set it up so it does this via the Form On Load Event Procedure with the following code:

    Me.totals = Form_frmDCPSub.txtQtyTotal

    However, this does not update the form on load. In fact the totals field doesn't update with anything at all???

  5. #5
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Hi

    Me.totals = Form_frmDCPSub.txtQtyTotal
    This expression doesn't look right to me.

    I think it should be
    Me.totals = YourSubFormName.Form!txtQtyTotal
    where YourSubFormName is the name of your subform.

    Check that you have set the Control Source property of the textbox called "totals" to "=YourSubFormName.Form!txtQtyTotal" then I think that is all you need.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

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

Similar Threads

  1. Me not picking up new columns in table
    By asterismw in forum Programming
    Replies: 3
    Last Post: 03-11-2011, 02:00 PM
  2. Print Single Record
    By stattech in forum Reports
    Replies: 5
    Last Post: 10-05-2010, 03:38 AM
  3. Single Record Reports (HELP)
    By bnckeye27 in forum Reports
    Replies: 1
    Last Post: 11-13-2009, 02:14 PM
  4. Help with Selecting a single record in access.
    By rfhall50 in forum Programming
    Replies: 3
    Last Post: 08-10-2009, 08:50 AM
  5. Adding a single record
    By kfoyil in forum Forms
    Replies: 2
    Last Post: 11-22-2006, 09:12 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