Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 20th, 2004, 08:31 PM
Authorized User
 
Join Date: Aug 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Running Sum

Hmm....I just want to ask one stupid question....I guess...:P

Can running sum be made in the continuous form?...What I mean is .. :-

No. Ref No. Name
------ ------- ------
           7601 Smith
           9098 Lisa
           6754 Charles
           ..etc ..etc

When there are 20 records in the rows, the "NO." will be numbered automatically 1 - 20.


TQ



 
Old July 21st, 2004, 05:18 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

Yes you can by using runsum()and dsum()

Here is an article that will walk you through the process
http://support.microsoft.com/?kbid=210338

ACC2000: Sample Function to Create a Running Sum on a Form
View products that this article applies to.
This article was previously published under Q210338
Moderate: Requires basic macro, coding, and interoperability skills.


SUMMARY
This article shows you how to create a sample user-defined function to compute a running sum on a form.
MORE INFORMATION
One way to compute a running sum on a form is to use the DSum() function. For additional information about how to use the DSum() function to compute a running sum on a form, please see the following article in the Microsoft Knowledge Base:
210495 ACC2000: How to Use DSum to Create a Running Sum on a Form

Using the method demonstrated in this article has the following advantages over using the DSum() function:
The method demonstrated in this article does not require a sequential ID field. A required sequential ID field limits you to computing a running sum using a single ordering of your records.
Using the method demonstrated in this article is significantly faster than using the DSum() function to compute a running sum.
How to Create and Use the RunSum() Function
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:
http://www.microsoft.com/partner/referral/

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:
http://support.microsoft.com/default...EN-US;CNTACTMS

NOTE: The sample code in this article uses Microsoft Data Access Objects. For this code to run properly, you must reference the Microsoft DAO 3.6 Object Library. To do so, click References on the Tools menu in the Visual Basic Editor, and make sure that the Microsoft DAO 3.6 Object Library check box is selected.


Open the sample database Northwind.mdb. Create a new module, and type the following line in the Declarations section if it is not already there:Option Explicit
Type the following code in the module: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
Create the following new query based on the Orders table and the Order Subtotals query. Save the query as qryOrders: Query: qryOrders
   ------------------------------------------------------
   Type: select query
   Join: Orders.[OrderID] <->; [Order Subtotals].[OrderID]

   Field: OrderID
      Table: Orders
      Sort: Ascending
   Field: Subtotal
      Table: Order Subtotals
Use the Form Wizard to create a new form based on the qryOrders query. Include both fields on the form. On the next screen click Tabular.
Add a text box with the following properties to the new form: Name: RunningSum
   ControlSource: =RunSum([Form],"OrderID",[OrderID],"Subtotal")
   Format: Currency
Save the form and then view it in Form view.
Select different records using the record selector. Note that the RunningSum field shows an accumulated total based on the Subtotal field.


 
Old July 21st, 2004, 09:17 PM
Authorized User
 
Join Date: Aug 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

TQ jemacc.. I really appreciate it...

C U!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Issue with a Running Sum MArgente Access 1 June 11th, 2007 06:45 AM
Running Sum in Subform Odeh Naber Access 2 May 14th, 2007 06:45 AM
"almost" a running sum I guess RobCarter SQL Server 2000 8 March 16th, 2007 02:00 AM
Help: Running Sum (or Cumulative Sum) timdasa VB Databases Basics 1 August 22nd, 2006 03:12 PM
SUM or What bertlf Pro VB Databases 2 November 29th, 2003 02:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.