Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do While loop missing last record

Status
Not open for further replies.

Sorwen

Technical User
Nov 30, 2002
1,641
US
I have a While loop (or Do Loop Until) that loops through records in an ADODB record set while .EOF <> True. For some reason it is returning true before the last record.

Code:
Do While rsTable1.EOF <> True
        Count2 = 0
        rsTable2.AddNew
        For Count = 0 To (rsTable1.Fields.Count - 1)
            rsTable2.Fields.Item(Count2).Value = rsTable1.Fields.Item(Count).Value
            Count2 = Count2 + 1
        Next Count
        rsTable1.MoveNext
        DoEvents
    Loop

The record set cannot return a count so I can't use a for loop. EOF shouldn't return as true until past the last record. Any ideas?

-I hate Microsoft!
-Forever and always forward.
 



Hi,

Try
Code:
Do 
        Count2 = 0
        rsTable2.AddNew
        For Count = 0 To (rsTable1.Fields.Count - 1)
            rsTable2.Fields.Item(Count2).Value = rsTable1.Fields.Item(Count).Value
            Count2 = Count2 + 1
        Next Count
        rsTable1.MoveNext
        DoEvents
Loop Unitl (rsTable1.EOF)


Skip,

[glasses] [red][/red]
[tongue]
 
Thanks, I had tried that and it didn't work. I found the problem however. What the problem seems to be is that addnew doesn't actually force the record set to add new. It only creates a new line for data to be added. The reason it was only dropping the last is that .addnew will force the record set to update before it adds a new line. So you still have to .update after the last. Adding .update allows either loop to work correctly. Thanks again for the help.

-I hate Microsoft!
-Forever and always forward.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top