Re: Bookmark Comparison Fails with Type mismatch

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Thanks for the response and the information leads, Allen. Additional
research confirms your opening statement; the bookmark appears to be more
robust and the method of choice in most situations. I'll consider it first
whenever faced with having to drop a "breadcrumb" in a recordset.

Thanks again,
Jay

"Allen Browne" wrote:

AbsolutePosition is inferior to bookmark, so I can't recommend that
approach.

Instead of using a For...Next loop with a counter, loop until EOF. This will
avoid the invalid bookmark message you received when you moved past the end
of the recordset.

Here's an example:
http://allenbrowne.com/func-DAO.html#DAORecordsetExample

There are other things that could fail, e.g. the MoveFirst will fail if
there are no records. More info in:
Traps: Working with Recordsets - 10 common mistakes
at:
http://allenbrowne.com/ser-29.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Jay" <Jay@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:F7C66163-318A-4FC8-ABFF-7D593330E7CB@xxxxxxxxxxxxxxxx
I've found an alternative that avoids the problem described in my original
post. Instead of using the Bookmark property and a comparison of bookmark
objects, I substituted the AbsolutePosition property and a comparision of
absolute positions:

1. replace 'varBookmark = .Bookmark'
with 'varAbsolutePosition = .AbsolutePosition'

2. replace 'Do Until .Bookmark = varBookmark'
with 'Do Until .AbsolutePosition = varAbsolutePosition'

It appears that operators (such as the = operation) can't be used with
Bookmarks.

Jay

"Jay" wrote:

Hi all –

The following code fails to compile when run. A ‘Type mismatch’ error
occurs on the 'Do Until…' statement.

With rs ‘valid recordset object
'load records
.MoveFirst: .MoveLast: .MoveFirst
'move to 10th record and capture its bookmark
For i = 1 To 9
.MoveNext
Next i
varBookmark = .Bookmark '10th record

'Step through records until bookmarked 10th
'record is found, starting at record 1.
.MoveFirst
Do Until .Bookmark = varBookmark
.MoveNext
Loop
MsgBox "Bookmarked record found."
End With

I’ve also tried the following alternative ‘Do Until’ statement, but it
also
fails to compile with a ‘Method or data member not found’ error even
though I
have set references to the MS ADO 2.5, 2.8, or ADORecordset 2.8
Libraries:

Do Until .CompareBookmarks(.Bookmark, varBookmark) = adCompareEqual


.



Relevant Pages

  • Re: Effects on RST in Calling Proc
    ... >> fail if the recordset itself remains valid. ... The bookmark property is available for the exact purpose ...
    (comp.databases.ms-access)
  • Re: Bookmark Comparison Fails with Type mismatch
    ... AbsolutePosition is inferior to bookmark, so I can't recommend that approach. ... Instead of using a For...Next loop with a counter, ... This will avoid the invalid bookmark message you received when you moved past the end of the recordset. ... There are other things that could fail, e.g. the MoveFirst will fail if there are no records. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Using Bookmarks
    ... I think, the bookmark is a property of a recordset, and the recordset ... 60-second refreshes are an ... > Private Sub Form_Timer ... > varBookMark = Me.Bookmark ...
    (microsoft.public.access.formscoding)
  • Bookmark Comparison Fails with Type mismatch
    ... The following code fails to compile when run. ... 'move to 10th record and capture its bookmark ... Do Until .Bookmark = varBookmark ...
    (microsoft.public.access.modulesdaovba)
  • RE: Bookmark Comparison Fails with Type mismatch
    ... Instead of using the Bookmark property and a comparison of bookmark ... The following code fails to compile when run. ... Do Until .Bookmark = varBookmark ...
    (microsoft.public.access.modulesdaovba)