Autonumber fields in MS Access

P

PD

Hello,

Can anyone tell me how to programatically reset the autonumber count in a
table in Access? I want to run a delete query to remove all rows, then
append rows and have the autonumber field begin counting at 1. I don't want
to make a new table with a new autonumber field, because I don't know how to
do that in a macro or a module (how to make a new table, define the fields,
create a new autonumber field). I have tried the method in the help file of
appending to the autonumber field and it doesn't work. The autonumber field
just picks up where it was before appending.

Thank you for your help.
 
O

Ofer Cohen

You can set the field back to counter after you delete the date

Delete statement
docmd.RunSQL "Alter table TableName ALTER COLUMN FieldName counter"
Insert Statemet
 
P

PD

Thank you so much. I appreciate it. When I tried to run I inserted the
table and field names like this:
DoCmd.RunSQL "Alter table Table1, ALTER COLUMN test counter"

And I got the following error message:

Syntax Error in Alter Table statement.

Is it an issue with enclosing the table and field names in quotes, or was I
supposed to do something with the counter at the end?

I really appreciate your help.
 
P

PD

Ofer,

Thank you so much. I removed the comma that I had inserted and it works
great! Are there any references to what is available in the RUNSQL function,
or is it just a matter of knowing SQL?

Thank you so much again for your help. I really appreciate it.
 
O

Ofer Cohen

Your welcome, glad it worked
In the RunSQL (as given by it's name) we run Action SQL such as
Create, Insert , Delete , Update , Alter
 
M

Marshall Barton

PD said:
Can anyone tell me how to programatically reset the autonumber count in a
table in Access? I want to run a delete query to remove all rows, then
append rows and have the autonumber field begin counting at 1. I don't want
to make a new table with a new autonumber field, because I don't know how to
do that in a macro or a module (how to make a new table, define the fields,
create a new autonumber field). I have tried the method in the help file of
appending to the autonumber field and it doesn't work. The autonumber field
just picks up where it was before appending.


Another way to reset an auto number after deleting records
is to Compact the database.

OTOH, you should not care what values are in an autonumber
field. If you do care about the values, you should create
them yourself instead of relying on a feature that was
intended for an entirely different purpose.
 

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