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]