looping

C

ChuckL02

In 2000 I am trying to write code to loop through data in a table, each time
it is created, and assign an Order By number to each record. I know I could
sort by the Index, but I would like the Order By Number to always start at 1
and continue to the end of the record set. I will not only use the order
number to sort the data, but to link to another table as well.

Here a simple example of what I'm working with:

Index Color OrderRecordsBy
52 Red
53 Blue
54 Yellow

I'm somewhat new to writing VBA, so any help would be greatly appreciated.
Thanks
 
A

Alex Dybenko

Hi,
something like this:

Dim rst As DAO.Recordset, i As Long
Set rst = CurrentDb.OpenRecordset("Select * from MyTable", dbOpenDynaset)
Do Until rst.EOF
i = i + 1
rst.Edit
rst!OrderRecordsBy = i
rst.Update
rst.MoveNext
Loop
rst.Close


--
Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.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