Create An incremented record in a table

M

Matty k

I have a table which I import data into. After the import i want to assign
each entry an incremented record number starting at 1, so that the first
entry will be record 1, the second will be 2, ect. How would i accomplish
this without the use of autonumbers?

Thank You for your help.
 
R

Rick Brandt

Matty k said:
I have a table which I import data into. After the import i want to assign
each entry an incremented record number starting at 1, so that the first
entry will be record 1, the second will be 2, ect. How would i accomplish
this without the use of autonumbers?

Thank You for your help.

(untested and w/o error handling)

Sub IncrementNumbers()

Dim rs As DAO.Recordset
Dim db As DAO.Database
Dim i As Long

Set db = CurrentDb
Set rs = db.OpenRecordset("TableName")
i = 1

Do Until rs.EOF
rs.Edit
rs!NumberField = i
rs.Update
rs.MoveNext
i = i + 1
Loop

rs.Close
Set rs = Nothing
Set db = Nothing

End Sub
 

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