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 / Database Design / April 2004

Tip: Looking for answers? Try searching our database.

reset autonumber value in table

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Elizabeth - 14 Apr 2004 14:25 GMT
Anyone have a routine to reset an autonumber field to 1?
Allen Browne - 14 Apr 2004 14:28 GMT
After deleting all records, compact the database:
   Tools | Database Utilities | Compact

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> Anyone have a routine to reset an autonumber field to 1?
Jeff Boyce - 14 Apr 2004 14:40 GMT
Elizabeth

Why?  If you're using/showing autonumbers and expect them to be
"meaningful", you'll be disappointed.  Access autonumbers are intended
primarily as arbitrary row identifiers, to allow tables to be related to
each other.

Signature

Good luck

Jeff Boyce
<Access MVP

- 14 Apr 2004 16:06 GMT
Because:
the tables in question are used in data load routines,
repeated at regular intervals.  The autonumber values
indeed are arbitrary row identifiers but grow to be very
large with each new load.

I queried newsgroup to see if anyone already set up a
routine -- in VB perhaps -- to reset the beginning value.

>-----Original Message-----
>Elizabeth
[quoted text clipped - 3 lines]
>primarily as arbitrary row identifiers, to allow tables to be related to
>each other.
Allen Browne - 15 Apr 2004 02:30 GMT
As well as just compacting the databsae, in Access 2000 and later you can
use ADOX to reset the Seed property of the AutoIncrement field.

Syntax to use in the Table of the Catalog:
   .Column("MyColumn").Properties("Seed") = 1

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> Because:
> the tables in question are used in data load routines,
[quoted text clipped - 4 lines]
> I queried newsgroup to see if anyone already set up a
> routine -- in VB perhaps -- to reset the beginning value.
Jeff Boyce - 15 Apr 2004 13:02 GMT
You must be doing some very seriously large loads, then.  I believe the
Access Autonumber uses values in the billions -- just how many rows are you
loading?!

Signature

Good luck

Jeff Boyce
<Access MVP

david epsom dot com dot au - 15 Apr 2004 10:19 GMT
ADOX example from Microsoft

Function ChangeSeed(strTbl As String, strCol As String, lngSeed As
Long) As Boolean
  'You must pass the following variables to this function.
  'strTbl = Table containing autonumber field
  'strCol = Name of the autonumber field
  'lngSeed = Long integer value you would like to use for next
autonumber.

  Dim cnn As ADODB.Connection
  Dim cat As New ADOX.Catalog
  Dim col As ADOX.Column

  'Set connection and catalog to current database
  Set cnn = CurrentProject.Connection
  cat.ActiveConnection = cnn

  Set col = cat.Tables(strTbl).Columns(strCol)

  col.Properties("Seed") = lngSeed
  cat.Tables(strTbl).Columns.Refresh
  If col.Properties("seed") = lngSeed Then
      ChangeSeed = True
  Else
      ChangeSeed = False
  End If
  Set col = Nothing
  Set cat = Nothing
  Set cnn = Nothing

  End Function

(david)

> Anyone have a routine to reset an autonumber field to 1?
- 29 Apr 2004 14:11 GMT
Thanks!  I will try this.

>-----Original Message-----
>ADOX example from Microsoft
[quoted text clipped - 35 lines]
>
>.
 
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



©2008 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.