Use Do while to loop through until EOF
Private Sub RunningSumDAO()
Dim db As Database
Dim rs As Recordset
Dim lRunningSum As Long
DBEngine.SetOption dbMaxLocksPerFile, 1000000
Set db = CurrentDb
lRunningSum = 0
Set rs = db.OpenRecordset("SELECT * FROM Employees ORDER BY FirstName")
Do While Not rs.EOF
rs.Edit
rs!RunningSum = lRunningSum
rs.Update
lRunningSum = lRunningSum + rs!Duration
rs.MoveNext
Loop
rs.Close
End Sub
Related examples in the same category