Running Sum

Runutts2

Registered User.
Local time
Today, 07:22
Joined
Aug 28, 2002
Messages
13
Need help, not sure if I am going about it the right way, and hope I can explain it well enough to make sense. Trying to take an Excel spreadsheet that has calculations in cells that are based on entries that add to the previous cell. And have the running sum to that point appear on each line on the form.
Example:

C3= A3 + B3 + C2
C4= A4 + B4 + C3

Have a from with the two fields A & B & KeyID field
But cant seem to use DlLookup for the calculated field C , also tried to use the RunSum fuction but can’t seem to get it to work.
 
In the recordsource property of fldC3 enter:

= Sum(fldA3+fldB3+fldC2)

You would need to add some error trapping in case there are null values the other fields. I'm not positive of the syntax, I don't have Access on the PC I am writing from so I can't test it.

HTH
 
I couldn't get that to work, comes up with #Name? error, fld and the field name with a space without a space with the field name in " " with the field name in [ ] couldn't get it to work.
 
I copied the following code from the forum, but can't get it to work either. gives #Name? error, Tried
=RunSum(Survey,"SurveyID",[SurveyID],"TVD")
but it puts the form name in backets like this
=RunSum([Survey],"SurveyID",[SurveyID],"TVD"

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 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
 
I still couldn't get that to work, do I need to apply a certain reference.
 
I finally got it, I had to place the code in the form module. I had just placed it as a new module before. Thanks again for the help
 
Getting closer, Well I got it to work with a field that is in a table, but can't get to work on a calculated field that was added just to the form. Is there another step that I have to do to get it to work.
 
The function should be in a standard module, not a form module.
You almost certainly have a problem with the references to your controls within the function.
You have to repeat the calculation such as
=(RunSum([Form],"DepID",[DepID],"Deposits"))-(RunSum([Form],"DepID",[DepID],"Deductions"))+[txtOpBal]
 
I still can't get what I am looking for, trying to get a running sum of a calculated field on a form. I am going to try and get it to work in the report, but would like to see the answer in the form .
 
hi,

i tried to make a duplicate of what you're trying to do and come up with a sample database, which i attached. pls. check if this is what you want. i use not code but query.

hope is suits your requirements.

your friendly embalmer,

joey
 

Attachments

I appreciate all the help I have received thus far, but what I just can’t figure out is how to have TVD, N / S, E / W give me the sum to that point using the TieTrueVerticalD, TieN/SCoordinates, and TieE/Wcoordinates as the starting point. I can get it to work on the first record using the IIf statement but then can’t get the totals on the records that follow. Not sure if I am even going about this task at the right approach. Here is a sample of what I have so far. Survey Main is the form i have been working on.

thanks again all
 

Users who are viewing this thread

Back
Top Bottom