Results 1 to 5 of 5
  1. #1
    Marin is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2013
    Posts
    4

    A running sum and filters

    Hello,

    I need a little help with an outcome of a running sum (cumulative total) after a filter has been applied.


    Click image for larger version. 

Name:	tbl1.jpg 
Views:	13 
Size:	19.0 KB 
ID:	11376
    Above is a simplified table on my report.
    After applied the date filter, lets say: Date = "Mar" I have got
    Click image for larger version. 

Name:	tbl2.jpg 
Views:	14 
Size:	8.3 KB 
ID:	11377

    But I need:
    Click image for larger version. 

Name:	tbl3.jpg 
Views:	13 
Size:	8.2 KB 
ID:	11378

    Any Ideas how to get an outcome from the last table?

    Thy

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Tried google to get a MsAccess running total in a report

    I found this http://office.microsoft.com/en-us/ac...005187388.aspx

    Good luck

  3. #3
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Here is an example of a running sum for a field. =RunSum([Form],"RegID",[RegID],"Amount")
    I use a module for this as well. Here is the code for the module if your interested. The mod is named ModRunSum

    Option Compare Database

    Function RunSum(F As Form, KeyName As String, KeyValue, _
    FieldToSum As String)
    '************************************************* **********
    ' FUNCTION: RunSum()
    ' PURPOSE: Compute a running sum on a form.
    ' PARAMETERS:
    ' F - The form containing the previous value to
    ' retrieve.
    ' KeyName - The name of the form's unique key field.
    ' KeyValue - The current record's key value.
    ' FieldToSum - The name of the field in the previous
    ' record containing the value to retrieve.
    ' RETURNS: A running sum of the field FieldToSum.
    ' EXAMPLE: =RunSum(Form,"ID",[ID],"Amount")
    '************************************************* **********
    Dim rs As DAO.Recordset
    Dim result

    On Error GoTo Err_RunSum

    ' Get the form Recordset.
    Set rs = F.RecordsetClone

    ' Find the current record.
    Select Case rs.Fields(KeyName).Type
    ' Find using numeric data type key value?
    Case DB_INTEGER, DB_Long, DB_CURRENCY, _
    DB_SINGLE, DB_DOUBLE, DB_BYTE
    rs.FindFirst "[" & KeyName & "] = " & KeyValue
    ' Find using date data type key value?
    Case DB_DATE
    rs.FindFirst "[" & KeyName & "] = #" & KeyValue & "#"
    ' Find using text data type key value?
    Case DB_TEXT
    rs.FindFirst "[" & KeyName & "] = '" & KeyValue & "'"
    Case Else
    MsgBox "ERROR: Invalid key field data type!"
    GoTo Bye_RunSum
    End Select

    ' Compute the running sum.
    Do Until rs.BOF
    result = result + rs(FieldToSum)

    ' Move to the previous record.
    rs.MovePrevious
    Loop

    Bye_RunSum:
    RunSum = result
    Exit Function

    Err_RunSum:
    Resume Bye_RunSum

    End Function

  4. #4
    chinaguy is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Jul 2013
    Posts
    1
    Hi Marin,

    I am looking for the same thing. Did you veer find a solution?

    Hope you did!

    Thanks.

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Did you try burrina's suggested code? Possible alternatives:

    A textbox in report header that sums all the records prior to Mar excluded by the filtered query. This can be in a subreport or DSum() function in textbox on main report. Then include that calculated value in the running sum textbox expression by reference to the textbox.

    Or try a nested subquery to get the aggregate calc. http://allenbrowne.com/subquery-01.html#YTD
    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.

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

Similar Threads

  1. Filters not running in Access 2010
    By Andrus_n in forum Queries
    Replies: 0
    Last Post: 01-26-2012, 07:00 AM
  2. Help with filters
    By daltman1967 in forum Forms
    Replies: 5
    Last Post: 07-14-2011, 02:12 PM
  3. Applicable Filters Box
    By Gray in forum Forms
    Replies: 0
    Last Post: 05-24-2011, 07:58 AM
  4. Form Filters Help
    By JeffG3209 in forum Forms
    Replies: 1
    Last Post: 05-22-2011, 10:31 PM
  5. About filters
    By registan in forum Forms
    Replies: 12
    Last Post: 04-09-2011, 08:01 AM

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