Finding the end of a recordset

C

CLamar

How do you find the end of a recordset, so it can be used in a loop. I tried
the EOF command but it wont enter the loop when i use it. Here is an example
of the code. The second for loop with the * is the one giving me problems

Set Recordset = New ADODB.Recordset
With Recordset
Src = "SELECT * FROM Table1"
.Open Source:=Src, ActiveConnection:=Connection

For Col = 0 To Recordset.Fields.Count - 1
Sheets("DataTable").Range("A1").Offset(0, Col).Value =
Recordset.Fields(Col).Name
Next

Sheets("DataTable").Range("A1").Offset(1, 0).CopyFromRecordset
Recordset

** For Row = 2 To Recordset.EOF
Sheets("Sheet1").LstBatchnum.AddItem
Sheets("DataTable").Cells(Row, 1)
Next Row
End With

Thanks
 
A

Arthur

** For Row = 2 To Recordset.EOF


use this instead
For Row = 2 To Recordset.RecordCount -1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top