Quotes from my files.
Reset autonumber
================================================
JeremyNYC (Programmer) 15 Sep 05 14:47
thread705-1122927
Keep in mind, though, that there is no reason to reset the autonumber field.
That number should NEVER be relied upon to present any kind of meaningful data.
Autonumbers are guaranteed (more or less) to be unique. They are NOT guaranteed
to be sequential, so the notion of assigning any significance to them is one
that will lead you down a dangerous path. See my write-up here for a bit more
detail:
- Jeremy
Resetting Autonumber
thread702-1122847
PHV (MIS) 15 Sep 05 5:43
reseting an autonumber field to 1
CurrentDb.Execute "ALTER TABLE yourTable ALTER COLUMN myID COUNTER(1,1)"
Reset Autonumber Field
thread702-1050735
apart from compact and repair
flyover789 (Programmer) 1 May 05 8:09
you don 't have to do the compact/repair thing. you can do it during runtime using the following code:
if your autonumber field (in the code I call it [ID]) is the primary key in your table, use:
Code
Function resetautonumber()
DoCmd.RunSQL "ALTER TABLE yourTable DROP CONSTRAINT [ID];"
DoCmd.RunSQL "ALTER TABLE yourTable DROP COLUMN [ID];"
DoCmd.RunSQL "ALTER TABLE yourTable ADD COLUMN [ID] COUNTER CONSTRAINT [ID] PRIMARY KEY;"
End Function
if it's not the primary key, use:
'Code
Function resetautonumber2()
DoCmd.RunSQL "ALTER TABLE yourTable DROP CONSTRAINT [ID];"
DoCmd.RunSQL "ALTER TABLE yourTable DROP COLUMN [ID];"
DoCmd.RunSQL "ALTER TABLE yourTable ADD COLUMN [ID] COUNTER CONSTRAINT [ID] UNIQUE;"
End Function
if you don't wish to index the ID field at all, use:
'Code
Function resetautonumber3()
DoCmd.RunSQL "ALTER TABLE yourTable DROP COLUMN [ID];"
DoCmd.RunSQL "ALTER TABLE yourTable ADD COLUMN [ID] COUNTER;"
End Function