Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2009
    Posts
    11

    Unanswered: Can you sum a column in a Subform

    i have a subforme with a column called Price. The values in this column are calculated via a dlookup formula. i would like to calculate the total of the price column but i do not now how can some one please help. thank you

  2. #2
    Join Date
    May 2005
    Posts
    1,191
    There may be a faster way that someone else may know of, but I know one way that has worked for me:
    Code:
    On Error GoTo ErrorHandler
        
        'instantiate variables
        Dim frm As Form
        Dim subfrm As Control
        Dim rst As DAO.Recordset
        Dim curTotal As Currency
        
        'initiate variables
        Set mainfrm = Forms!frmMainName
        Set subfrm = mainfrm!frmSubName
        Set rst = subfrm.Form.RecordsetClone
        
        'cycle through rst and calc total
        curTotal = 0
        rst.MoveFirst
        While Not rst.EOF
            curTotal = curTotal + Nz(rst!Price, 0)
            rst.MoveNext
        Wend
        
        ' do whatever with curTotal
        
    ExitProc:
        Set rst = Nothing
        Exit Sub
        
    ErrorHandler:
        On Error Resume Next
        docmd.beep
        GoTo ExitProc
    Just be sure to name the variables according to your situation.
    Me.Geek = True

  3. #3
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,420
    Provided Answers: 7
    create a footer on the form then put a text box

    =sum([theformfeildnameyouwanttosumup])
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

  4. #4
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Agreed with myle.

    Just make sure your DLookup is being done in the QUERY, not the form and you will be able to sum it with a sum function.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •