By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,080 Members | 1,817 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,080 IT Pros & Developers. It's quick & easy.

bookmark problem

P: n/a
(Access 97 and 2003)

Hi,

Here's a smippit of code that works correctly about 95% of the time.
This part of the algorithm...

- find the first value = true
- if found, find next value = false
- if found, find next value = true
- go back and fill the falses between the 2 trues to true (not all
code obviously there)

The problem is that in rare cases the last line provided here "Do
Until (bk1 = bk2)" is TRUE the FIRST time through the loop when it
should be FALSE. This is using identical data, identical sort. One
out of 20 or so times the bookmark set for 2 different records seems
to be the same! Then the next time I run the procedure (immediately
following the errant trial) it works fine. And yes, there are TRUES
with FALSES "between" them when the falure occurs.

...
rs.FindFirst "Batch = " & True
If rs.NoMatch Then Exit Sub
bk1 = rs.Bookmark
Do Until rs.EOF
rs.FindNext "Batch = " & False
If rs.NoMatch Then Exit Do
rs.FindNext "Batch = " & True
If rs.NoMatch Then Exit Do
bk2 = rs.Bookmark
rs.Bookmark = bk1
Do Until (bk1 = bk2)
...

No records have been deleted.
I also tried requering and movelast followed by movefirst before the
code snipit above, no dice.

Of course I could come up with a different algorighm, but shouldn't
the above work reliably?

Thanks!

Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Suggestions:

1. What is rs? Is it a DAO recordset, just opened on a query that includes:
ORDER BY Batch
Is it something that is already open (e.g. the RecordsetClone of a form)? If
so, then the initial bookmark could be pointing somewhere other than the
first record.

2. What Option statement exists in this module? Does it make any difference
if you use a binary comparison on the bookmarks, i.e.:
Do Until StrComp(bk1, bk2, vbBinaryCompare) = 0

3. A well-designed procedure should have one entry point and one exit point.
Your "Exit Sub" statements mean that the routine may not be cleaning up
after itself (e.g. closing the recordset if you opened it). Does changing
that make any difference.

4. Would it be more efficient to just open a recordset that chooses the
records you want (i.e. just the ones where Batch is True?)? Or could you do
this by executing an Update query statement instead of a loop?

--
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.

"DrFoo" <ar*@bc.com> wrote in message
news:us********************************@4ax.com...
(Access 97 and 2003)

Hi,

Here's a smippit of code that works correctly about 95% of the time.
This part of the algorithm...

- find the first value = true
- if found, find next value = false
- if found, find next value = true
- go back and fill the falses between the 2 trues to true (not all
code obviously there)

The problem is that in rare cases the last line provided here "Do
Until (bk1 = bk2)" is TRUE the FIRST time through the loop when it
should be FALSE. This is using identical data, identical sort. One
out of 20 or so times the bookmark set for 2 different records seems
to be the same! Then the next time I run the procedure (immediately
following the errant trial) it works fine. And yes, there are TRUES
with FALSES "between" them when the falure occurs.

...
rs.FindFirst "Batch = " & True
If rs.NoMatch Then Exit Sub
bk1 = rs.Bookmark
Do Until rs.EOF
rs.FindNext "Batch = " & False
If rs.NoMatch Then Exit Do
rs.FindNext "Batch = " & True
If rs.NoMatch Then Exit Do
bk2 = rs.Bookmark
rs.Bookmark = bk1
Do Until (bk1 = bk2)
...

No records have been deleted.
I also tried requering and movelast followed by movefirst before the
code snipit above, no dice.

Of course I could come up with a different algorighm, but shouldn't
the above work reliably?

Thanks!

Nov 13 '05 #2

P: n/a
On Sun, 5 Dec 2004 16:29:14 +0800, "Allen Browne"
<Al*********@SeeSig.Invalid> wrote:
2. What Option statement exists in this module? Does it make any difference
if you use a binary comparison on the bookmarks, i.e.:
Do Until StrComp(bk1, bk2, vbBinaryCompare) = 0
Thats it! Thanks.

My hunch is that there are null terminators (CHAR 0) or some other
special non-text characters in the bookmarks that cause Access to
stop reading as a string, thus the direct comparison using "=" will on
rare cases fail.

3. A well-designed procedure should have one entry point and one exit point.
Your "Exit Sub" statements mean that the routine may not be cleaning up
after itself (e.g. closing the recordset if you opened it). Does changing
that make any difference.


There was only one Exit Sub, but true, it was sloppy.

Nov 13 '05 #3

P: n/a
DrFoo <ar*@bc.com> wrote in
news:kc********************************@4ax.com:
On Sun, 5 Dec 2004 16:29:14 +0800, "Allen Browne"
<Al*********@SeeSig.Invalid> wrote:
2. What Option statement exists in this module? Does it make any
difference if you use a binary comparison on the bookmarks, i.e.:
Do Until StrComp(bk1, bk2, vbBinaryCompare) = 0


Thats it! Thanks.

My hunch is that there are null terminators (CHAR 0) or some other
special non-text characters in the bookmarks that cause Access to
stop reading as a string, thus the direct comparison using "="
will on rare cases fail.


I've never once felt any need to examine the actual content of a
bookmark.

In my opinion, any requirement to do so means that you are using
bookmarks in the wrong way.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.