Need help with do while loop

G

Guest

I'm using ADO to retrieve records from an access table and store them in an
excel sheet. The following line of code populates all records at once.

Worksheets("sheet2").Range("A1").CopyFromRecordset rst

Can someone help me in writing a do while loop that will populate one record
at a time. I want the record to only write to the same cell each time. Yes,
the record will write over the previous one until it reaches the last record.
Thanks.
 
D

Dick Kusleika

Markantesp

Do While Not rs.EOF
Range("A1").Value = rs.Fields(0).Value
Range("B1").Value = rs.Fields(1).Value
etc..
rs.MoveNext
Loop

Where rs is the variable that holds your recordset.
 
O

Oliver Ferns via OfficeKB.com

oops....
sorry!


What I meant was try this..


With RS
If not .BOF then .MoveFirst
 
G

Guest

thankyou!

Dick Kusleika said:
Markantesp

Do While Not rs.EOF
Range("A1").Value = rs.Fields(0).Value
Range("B1").Value = rs.Fields(1).Value
etc..
rs.MoveNext
Loop

Where rs is the variable that holds your recordset.

--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com
 

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