Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 2 / January 2008

Tip: Looking for answers? Try searching our database.

Re-set autonumber in a table (primary key)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Biffo - 11 Jan 2008 19:25 GMT
I have built a database and tested it thoroughly. I deleted the test records
but now my first record has an automunber or 15 and this is winding me up.
Can I re-set the autonumber back to 0?
Bob Barnes - 11 Jan 2008 19:29 GMT
Try a compact and repair on the DB (front- or back-end) having that table.

> I have built a database and tested it thoroughly. I deleted the test records
> but now my first record has an automunber or 15 and this is winding me up.
> Can I re-set the autonumber back to 0?
Wayne-I-M - 11 Jan 2008 19:30 GMT
Delete the field.  Save the table.  Insert a new autonumber field

Signature

Wayne
Manchester, England.

> I have built a database and tested it thoroughly. I deleted the test records
> but now my first record has an automunber or 15 and this is winding me up.
> Can I re-set the autonumber back to 0?
Krzysztof Pozorek [MVP] - 11 Jan 2008 20:25 GMT
> Delete the field.  Save the table.  Insert a new autonumber field

...or you can simply execute something like this:
DoCmd.RunSQL "alter table Table1 alter column ID counter(1,1)"

For example counter(3, 10) means:
3 - initial value of counter
10 - step value.

K.P. MVP, Poland
www.access.vis.pl
Wayne-I-M - 11 Jan 2008 21:35 GMT
Why not not just
Delete the field.  Save the table.  Insert a new autonumber field
Much better for someone who has no records in a table that has just been
created.

Mind you I never really bother what an autonumber field has in it.  As long
as it's unique - thas all I'm bothered about.

You could also compact the DB

You could also ....etc etc

But still think it's better when 1st createing a table to ...
Delete the field.  Save the table.  Insert a new autonumber field

Signature

Wayne
Manchester, England.

> > Delete the field.  Save the table.  Insert a new autonumber field
>
[quoted text clipped - 7 lines]
> K.P. MVP, Poland
> www.access.vis.pl
Krzysztof Pozorek [MVP] - 11 Jan 2008 23:05 GMT
(...)
> Why not not just
> Delete the field.  Save the table.  Insert a new autonumber field
[quoted text clipped - 11 lines]
> But still think it's better when 1st createing a table to ...
> Delete the field.  Save the table.  Insert a new autonumber field

Your advice is good and I agree with this, what you wrote.
Although, what it is better, it depends on what You need at that moment.
The "alter table... " gives the easy possibility of steering the counter
with code. So it is less well-known than compact or recreate the autonumber
field. Therefore I mentioned about it.

Kris, Poland
www.access.vis.pl
Wayne-I-M - 12 Jan 2008 14:17 GMT
Hi Krzysztof

You are correct if there are relationships.  You method would be better as
mine would cause problems.  I assumed it was a new stand alone table.

Signature

Wayne
Manchester, England.

> (...)
> > Why not not just
[quoted text clipped - 21 lines]
> Kris, Poland
> www.access.vis.pl 
Steve Schapel - 12 Jan 2008 00:10 GMT
Wayne,

I prefer the advice given by Bob, to simply Compact the database.  Your
idea is more difficult, but still fine, but could get further
complicated if this table has Relationships defined based on this
Autonumber field, etc.

Signature

Steve Schapel, Microsoft Access MVP

> Why not not just
> Delete the field.  Save the table.  Insert a new autonumber field
[quoted text clipped - 10 lines]
> But still think it's better when 1st createing a table to ...
> Delete the field.  Save the table.  Insert a new autonumber field
Wayne-I-M - 12 Jan 2008 14:16 GMT
Hi Steve

Yes you are right.  I assumed it was a stand along table.  -  Is it too late
to make a new year's resolution - don't make assumptions.  :-)

Signature

Wayne
Manchester, England.

> Wayne,
>
[quoted text clipped - 17 lines]
> > But still think it's better when 1st createing a table to ...
> > Delete the field.  Save the table.  Insert a new autonumber field
Steve Schapel - 13 Jan 2008 02:07 GMT
Hi Wayne,

On the other hand, I am only right if one makes the assumption ;-) that
they are using Access 2003 or earlier.  It appears that compacting the
database does not re-set the Autonumber seed in Access 2007!

Signature

Steve Schapel, Microsoft Access MVP

> Hi Steve
>
> Yes you are right.  I assumed it was a stand along table.  -  Is it too late
> to make a new year's resolution - don't make assumptions.  :-)
Steve Schapel - 13 Jan 2008 02:17 GMT
Oooopos!!  Correction - sorry!! That is not correct.  I was testing on a
remote server, which was somehow messing things up.  When doing it
locally, it behaves as in earlier versions - I should have paused before
posting!

Signature

Steve Schapel, Microsoft Access MVP

> Hi Wayne,
>
> On the other hand, I am only right if one makes the assumption ;-) that
> they are using Access 2003 or earlier.  It appears that compacting the
> database does not re-set the Autonumber seed in Access 2007!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.