Loop through recordset

  • Thread starter Thread starter Razor
  • Start date Start date
R

Razor

Hi,

I have written a query that needs to be opened as a one-
column recordsource through code.

A code fragment needs to be run on each record of the
recordset, then moving to the next record and doing the
same until I reach the end of the recordset.

Could you give me the code that will open the recordset
for a line of sql and show how to loop through it?

Thanks,

Razor
 
Yes, I can, but there may be a much better way. What is the line of code
doing to the value in this field? If it is something that can be
incorporated into an Update Query, it will run MUCH MUCH faster.
 
Hi,
Dim strSql As String
Dim rs As DAO.Recordset

strSql = "Select * From yourTable"

Set rs = CurrentDb.OpenRecordset strSql

rs.MoveFirst
Do While Not rs.EOF
'your code here
rs.MoveNext
Loop

Set rs = Nothing

Look up the OpenRecordset method in Help because there are other options you should be aware of.
 
Back
Top