The reason you get errors with the For Loop is because the check for EOF occurs before the MoveNext. Always check for EOF/BOF after moving to a new record. When the For Loop exits EOF will be True. Calling the Update method when EOF is true will cause an error because there is no current record. All records will have been successfully modified already.
There is no need to call the Update method directly but it does no harm if you do. ADO automatically calls Update when the record position changes, or the recordset is being closed, and the current record has been updated/inserted.
I would have written this code with a Do Loop.
But this code should work just as well assuming the RecordCount property is valid. RecordCount may be equal to -1 depending on how you opened the recordset.Code:With adoPrimaryRS .MoveFirst Do Until .EOF .Fields(0) = .AbsolutePosition .MoveNext Loop End With 'At this point the recordset is at EOF.
Code:adoPrimaryRS.MoveFirst For i = 1 To adoPrimaryRS.RecordCount adoPrimaryRS.Fields(0) = i adoPrimaryRS.MoveNext Next




Reply With Quote