473,497 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Running Sum

1 New Member
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 2709
AdrianJ1980
13 New Member
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
6899
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
10326
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
5752
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
5991
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
1784
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
1543
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
4153
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
11268
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
4628
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
8116
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
7121
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
6993
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6881
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4584
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.