Bookmark comparison

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I don't understand why the following code generates a 'Type mismatch' error:

Dim rs as DAO.recordset
dim varTemp as variant

'(rs opened and moved to a record)

varTemp = rs.Bookmark 'Note a record

'(In later code after moving around recordset)

If rs.Bookmark = varTemp then
'Confirm on tagged record

'Code..........

End If


The line 'If rsBookmark = varTemp Then' gives a type mismatch error with the
'=' highlighted.

The reason I am using this line is because as I am processing through the
recordset, I may need to add some new records. Because these added records
are placed at the end of the rs, I need to know what is the first added
record bookmark, otherwise I will 'reprocess' these added records.

So my alternate question is, is this the best method for handling this
situation? To close and re-open the rs each time is to slow. To add a record
then remove it from the recordset would also work (But not delete it from the
table).

I hope this is clear. I can provide more complete code if needed.

Thanks in advance.


swas
 
The recordset might not have a current bookmark.

That can happen after adding a new record, deleting a record, moving before
the first record, moving after the last record, using a Find method or Seek
that results in NoMatch, or if the recordset is loaded/filtered such that it
has no records.

Alternatively, the bookmark may be out of date if the recordset has been
reopened, requeried, or reassigned.

After sorting that out, it might be safer to perform a binary comparison
If StrComp(rs.Bookmark, varTemp, vbBinaryCompare) = 0
since bookmarks are binary data.
 
Allen,

Thanks for that.

I definately have a current record, and your StrComp allows the comparison.

Not sure why the comparison I used didn't work, but as usual your help is
appreciated.


swas
 
Back
Top