Do while loop problem

Malcy

Registered User.
Local time
Today, 22:31
Joined
Mar 25, 2003
Messages
584
I need to sequentially process a recordset from bottom to top and then once all records completed I need to go back to the first record and set a flag within the record.
It works fine until the last bit. On investigating I have found that assuming 4 records it runs through the records four times fine but then tries to run through a 5th time and so falls over.
I start the loop with
Code:
' Set flag on last dosette dispensing date
    rstDld.MoveLast

' Sequentially process dosette labels from last to first
    Do While Not rstDld.BOF And Not rstDld.EOF
' Set flag for new record
            rstDld.Edit
                rstDld!bDosLab = -1
                
                rstDld.Update
and then all sorts of bits in the middle and I end it with
Code:
' Move to previous record unless already on first record
        rstDld.MovePrevious
                
    Loop

'Reset the first date back to yes
            rstDld.MoveFirst
            
            rstDld.Edit
                    rstDld!bDosLab = -1
                
                rstDld.Update
        
' Close the recordset
        rstDld.Close

Anyone got any ideas what i have got wrong here? It is rather doing my head in!
Thanks
 
I need to sequentially process a recordset from bottom to top and then once all records completed I need to go back to the first record and set a flag within the record.
It works fine until the last bit.
From the code that you've listed, I'm not quite sure what the problem is. Looks like you're trying to loop through from bottom to top, and set checkboxes to "yes".

What about the bit of the code looping through the set 4 or 5 times? Can you explain this?

What does the phrase then all of the "stuff" in between mean? In your first section of code, there is no .movenext or .moveprevious. Why not? if you're looping, one of those two should be in there...

I don't see anything in the code that would cause a problem, unless I missunderstand the problem at hand...
 
My question would by why not just use an UPDATE Query (SQL Statement) to update all of the applicable records in one quick shot. No iteration through the records is necessary. It's faster and way more efficient.
 
My question would by why not just use an UPDATE Query (SQL Statement) to update all of the applicable records in one quick shot. No iteration through the records is necessary. It's faster and way more efficient.
Me too, but something is fishy there. Something tells me that's not all that's going on here, but it sure looks like it from reading the words on the screen! :)
 
Thanks for input. You are right there is more going on. I need to print sticky labels in a very specific order off a roll of labels.
Fundamentally first out I need one dispensing label and two bag labels for the last issue in a sequence, then the same for the penultimate and so on until this particular sequence ends up with the first issue in the sequence.
I then need to use the record which sparks off the first issue to generate a new set of sequential labels - hence the need to re-flag it.

By going through four times ok what I mean is it generates the required sequence of labels exactly as required until it has printed the labels for the first issue. It is then already on the first record in the recordset but when it hits the rstDld.MovePrevious is loops back to the Do While and somehow it is not recognised as BOF so then tries to run the first line of the code to edit the record - and of course there isn't one.
I would normally look to using an update query but cannot quite see how to generate this very specific sequence of labels without working on the records in reverse sequence.
Does this clarify a bit?
 
Now sorted thanks
Changed to doing a dcount of the recordset and and incremental counter which seems to have solved the thing (after a few false starts!)
Thanks for the help
Best wishes
 

Users who are viewing this thread

Back
Top Bottom