Create An incremented record in a table

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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
 
Back
Top