Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a column of consecutive numbers

Status
Not open for further replies.

bluemat

Technical User
Feb 5, 2002
61
0
0
MX
I have a large database with 140, 000 records in it. I would like to give each one a consecutive ID, so I would like to add a new column with consecutive numbers 1 - 140,000

help?

thanks
 
I would have thought that autonumber is the obvious answer...! Is there a reason why you havent tryed this?
 
I have tried but the database is too big to do al records. And I cannot manually update certain records and auto number the rest....
 
Try this. You need a valid SQL statement that allows updates to your table (updateable recordset SQL where the red text is) and the name of the field (where the green text is):
[tt]
strSQL = “SELECT ….”
Set dbs = OpenDatabase(CurrentDb.Name)
Set qdf = dbs.CreateQueryDef("", strSQL)
Set rst= qdf.OpenRecordset(dbOpenDynaset)

If rst.BOF = False Then
rst.MoveLast
lngMaxRec = rst.RecordCount
rst.MoveFirst
Else
lngMaxRec = 0
End If

For i = 1 To lngMaxRec


With rst
.Edit
!RecRef = i
.Update
.Bookmark = .LastModified
End With
'-------------------
rst.MoveNext
Next i

rst.close
qdf.close
dbs.close
set rst = Nothing
set qdf = Nothing
set dbs = Nothing

Beep
Msgbox “End of update”
[/tt]
[/tt]
[/tt]

hth,
GGleason
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top