473,405 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Running Sum

I have searched for an answer but have failed to come up with anything that seems to work.

I am trying to set up an Access 2003 database for home accounts. I want to create a running sum (a balance based on what has been spent or paid in).

I have a table called tblCardBankPymnts. In that I have a Figure column for what transaction has been done. I also have a Balance column but think I should not have this now.

I then have a form to fill this in and I think it is on this form I need to have the Running Sum in the Balance text box.

I came across the following VBA code and added the following into a new module called modRunSum:

Expand|Select|Wrap|Line Numbers
  1.  Option Explicit 
  2. Public Function frmRunSum(curForm As Form, idName As String, _
  3. idValue, sumField As String)
  4. '***********************************************************
  5. '* curForm - Always 'Me' for easy setting of form object. *
  6. '* idName - Unique fieldname (usually primarykey). *
  7. '* idValue - Value of idName. *
  8. '* sumField - The name of the field to runsum *
  9. '***********************************************************
  10. Dim rst As DAO.Recordset, subSum
  11.  
  12. Set rst = curForm.RecordsetClone
  13.  
  14. 'Find the current record via proper syntax for Data Type.
  15. Select Case rst.Fields(idName).Type
  16. Case dbLong, dbInteger, dbCurrency, _
  17. dbSingle, dbDouble, dbByte 'Numeric Data Type
  18. rst.FindFirst "[" & idName & "] = " & idValue
  19. Case dbDate 'Date Data Type
  20. rst.FindFirst "[" & idName & "] = #" & idValue & "#"
  21. Case dbText 'Text Data Type
  22. rst.FindFirst "[" & idName & "] = '" & idValue & "'"
  23. Case Else
  24. rst.MovePrevious 'Set BOF!
  25. End Select
  26.  
  27. 'Running Sum (subTotal) for each record occurs here.
  28. Do Until rst.BOF
  29. subSum = subSum + Nz(rst(sumField), 0)
  30. rst.MovePrevious
  31. Loop
  32.  
  33. frmRunSum = subSum
  34.  
  35. Set rst = Nothing
  36.  
  37. End Function
  38.  
I then added the following into the Form_frmCardBankPymnts Class Object in the VBA window:

Expand|Select|Wrap|Line Numbers
  1.  Public Function frmCardBankPymnts() 
  2.  
  3. '*******************************************************************
  4. '* idName - Unique field name. *
  5. '* sumField - The name of the field to runsum *
  6. '*******************************************************************
  7.  
  8. If Not IsNull(Me!Balance) Then 'Skip New Record!
  9. frmCardBankPymnts = frmRunSum(Me, "Balance", Me!Balance, "Figure")
  10. End If
  11.  
  12. End Function
  13.  
On the frmCardBankPymnts form (used to enter the data into the tblCardBankPymnts table) in the Balance textbox Control Source box I then have: =frmCardBankPymnts()

I have a start figure in row one of the tblCardBankPymnts in the Figure column of 100 pounds and then in the next row a figure of 50 pounds. Yet, on the form it displays 100 pounds in each of the rows, not 150 as I would have expected.

Can anyone help please? I see in Access 2007 there is a Running Sum funtion, but in Access 2003 this does not exist.

Many thanks

Brian Miller
Jul 13 '07 #1
1 2700
It's easy to do in a report through the properties menu as per http://office.microsoft.com/en-us/ac...873881033.aspx
Dec 18 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Ross Presser | last post by:
OK, I've been researching this problem and can't find a definitive answer yet. The situation is one that seems to have come up a few times to different folks. I am writing an application that...
4
by: Bill Dika | last post by:
Hi I am trying to calculate a running total of a calculated textbox (tbAtStandard) in GroupFooter1 for placement in a textbox (tbTotalAtStandard) on my report in Groupfooter0. The problem...
1
by: Ennio-Sr | last post by:
Hi all! Testing a script where I need to make sure that postgresql is running before passing a <psql dbasename -c "insert into ..." > instruction I faced this curious behaviour: This is the...
1
by: Anonieko | last post by:
Query: How to display progress bar for long running page Answer: Yet another solution. REFERENCE: http://www.eggheadcafe.com/articles/20050108.asp My only regret is that when click the...
7
by: pradeep_TP | last post by:
hello all, I want to know how can I check whether a web site us running or not. I have used HttpWebRequest but when I give a web site address, It takes few number of seconds to throw exception...
3
by: Anil Kumar Sharma | last post by:
Hello, I am working on C# using vs.net 2003. I have faced two interesting problems. 1. Dynamically setting Default Button: I created a form and used it in various contexts. On basis of the...
4
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to...
16
by: Gandalf186 | last post by:
I need to create a query that produces running totals for every group within my table for example i wish to see: - Group A 1 5 9 15 Group B
2
by: upperclass | last post by:
Hi, I'm trying to find a decent way to measure program running time. I know clock() is probably the standard way of doing it but clock_t overflows too quickly. The target program running time...
1
by: =?Utf-8?B?Q2lhcmFuIE8nJ0Rvbm5lbGw=?= | last post by:
On reflection, you could possibly make the app a self extracting zip file which extracts the EXE and a settings file and then starts the app, then when you app closes, it can repack the settings...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.