Use Do while to loop through until EOF : Recordset Seek « Access « VBA / Excel / Access / Word






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

1.Finding Records Using the Seek Method (Seek constants)
2.Use seek method in Recordset