Is this recordset coding ok?

  • Thread starter Thread starter mscertified
  • Start date Start date
M

mscertified

Is the fields collection still available after .update?

On Error GoTo TryNext
Do While Not rs.EOF
If Nz(rs.Fields("LockUser").Value, "") = "" Then
With rs
.Fields("LockUser").Value = strUser
.Update
lngQID = .Fields("ID").Value <====== ???
.Close
End With
Exit Do
End If
TryNext:
rs.MoveNext
Loop
On Error GoTo 0
 
The documentation states this this is not safe code, but I can't recall the
specifics where it failed and in what versions. Perhaps it was when adding a
new record.

To avoid the issue, use:
.Bookmark = .LastModified
after the .Update.

Other common mistakes:
VBA Traps: Working with Recordsets
at:
http://allenbrowne.com/ser-29.html
(There is is: #8 on that page.)
 
Back
Top