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 yourtable, 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 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] UNIQUE;"
End Function
if you don't wish to index the ID field at all, use:
Code:
Function resetautonumber()
DoCmd.RunSQL "ALTER TABLE yourTable DROP COLUMN [ID];"
DoCmd.RunSQL "ALTER TABLE yourTable ADD COLUMN [ID] COUNTER;"
End Function
hth,
fly
[blue]Typos, that don't affect the functionality of code, will not be corrected.[/blue]
________________________________________
Zameer Abdulla Visit Me A child may not be able to lift too much.
But it can certainly hold a marriage together
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.