Connecting Tech Pros Worldwide Forums | Help | Site Map

bookmark problem

DrFoo
Guest
 
Posts: n/a
#1: Nov 13 '05
(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!

Allen Browne
Guest
 
Posts: n/a
#2: Nov 13 '05

re: bookmark problem


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" <arg@bc.com> wrote in message
news:usr4r0pr6e5ufidfcmq8253eu4cfd5vfqg@4ax.com...[color=blue]
> (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![/color]


DrFoo
Guest
 
Posts: n/a
#3: Nov 13 '05

re: bookmark problem


On Sun, 5 Dec 2004 16:29:14 +0800, "Allen Browne"
<AllenBrowne@SeeSig.Invalid> wrote:
[color=blue]
>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[/color]

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.
[color=blue]
>
>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.[/color]

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

David W. Fenton
Guest
 
Posts: n/a
#4: Nov 13 '05

re: bookmark problem


DrFoo <arg@bc.com> wrote in
news:kca6r0lgk89vefp9kelcpc1plc8l5aq9lv@4ax.com:
[color=blue]
> On Sun, 5 Dec 2004 16:29:14 +0800, "Allen Browne"
><AllenBrowne@SeeSig.Invalid> wrote:
>[color=green]
>>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[/color]
>
> 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.[/color]

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
Closed Thread


Similar Microsoft Access / VBA bytes