Bookmark Invalid

  • Thread starter Thread starter JimS
  • Start date Start date
J

JimS

Using the following code, I get an Invalid Bookmark error. It appears to
happen on the last row of the filtered ADODB recordset on the "Movenext"
method...:

rstPickListDetail.Open "tblPickListDetail", cnn, adOpenDynamic,
adLockOptimistic
....
....
rstPickListDetail.Filter = "PLPicklistID=" & m_lngPicklistID
While Not rstPickListDetail.EOF
rstPickListDetail.Delete
rstPickListDetail.MoveNext
Wend
 
Why use a recordset for that? You'd be much better off simply issuing a
DELETE statement.

If you feel you must use a recordset, you need to start at the last record
and move forward to the first one:

rstPickListDetail.Filter = "PLPicklistID=" & m_lngPicklistID
rstPickListDetail.MoveLast
While Not rstPickListDetail.BOF
rstPickListDetail.Delete
rstPickListDetail.MovePrev
Wend

This is because when you delete the record, that record obviously can no
longer be the current row, so Access needs to move the current row pointer.
When you're going forward as you were, the pointer will end up at EOF when
you delete the last record in the recordset, so the MoveNext statement tries
to go past EOF.
 
Back
Top