Looping table until end

Paul Wagner

Registered User.
Local time
Today, 14:43
Joined
May 18, 2004
Messages
48
How do I loop through a small table plucking out the key until no more records? At each pass I want to perform an insert into another table (I think I've got that part down...just don't know how to loop through a table)

TIA!!
 
Paul,

Code:
Dim dbs As DAO.Database
Dim rst As DAO.RecordSet

Set dbs = CUrrentDb
Set rst = dbs.OpenRecordSet("Table1")

While Not rst.EOF and Not rst.BOF
   DoCmd.RunSQL "Insert Into Table2 (TheKey) Values (" & rst.TheKey & ")"
   rst.MoveNext
   Wend

Wayne
 

Users who are viewing this thread

Back
Top Bottom