Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
[blue]Option Explicit[/blue]
[blue]Public Function frmRunSum(frm As Form, pkName As String, sumName As String)
Dim rst As DAO.Recordset, fld As DAO.Field, subTotal
Set rst = frm.RecordsetClone
Set fld = rst(sumName)
[green]'Set starting point.[/green]
rst.FindFirst "[" & pkName & "] = " & frm(pkName)
[green]'Running Sum (subTotal) for each record group occurs here.
'After the starting point is set, we sum backwards to record 1.[/green]
If Not rst.BOF Then
Do Until rst.BOF
subTotal = subTotal + Nz(fld, 0)
rst.MovePrevious
Loop
Else
subTotal = 0
End If
frmRunSum = subTotal
Set fld = Nothing
Set rst = Nothing
End Function[/blue]
[blue]Private Function SubSum()
[green]'*************************************************************
'* pkName - Existing [b]unique fieldname[/b] (usually primarykey) *
'* sumName - Name of the field to runsum *
'*************************************************************[/green]
If Trim(Me![purple][b]pkName[/b][/purple] & "") <> "" Then [green]'Skip New Record![/green]
SubSum = frmRunSum(Me, "[purple][b]pkName[/b][/purple]", "[purple][b]sumName[/b][/purple]")
End If
End Function[/blue]
[purple]=[b]SubSum[/b]()[/purple]
[blue] DoEvents
Me.Recalc[/blue]