DataBase - Autonumber restarting after compact and repair

Asked By Boon
08-Feb-10 05:07 PM
Hello,

Here is my situation.

I have table A that has the field ID as the first field. The field ID is the
AutoNumber and it is a primary key. Table A also has several fields in the
table (name, date,shipping date......)

The table A has  2000 records. Today, I worked in table A and removed some
records....  Then I compact and repaired the database. Now when adding new
data into the table A, the field ID did not start at 2001. It started at (I
think) the first missing number in the sequence. Also when I append the new
data to the table A, all the weird things happen. For instance, says I have
3 new records, and the I have 3 consecutive numbers in the sequence that are
still available as a key in field ID, I can append all 3 records. But say if
I have 3 records and I have only 2 consecutive numbers in a sequence, Access
appends just 2 records. I know this is confusing. I am still confused...

How can I work around this? I want to use AutoNumber field, but at the same
time, I want to be able to compact and repair and want the autonumber starts
at the highest number in the field ID..

thanks,
Boon
Database
(1)
Appends
(1)
  Jeff Boyce replied to Boon
08-Feb-10 07:10 PM
Access Autonumbers are designed to serve as unique record/row identifiers
... nothing else.

They are unfit for human consumption, so if have an autonumber = "2001"
means something to you, it is time for a redesign!

Autonumbers start over at the next highest value after compact/repair.
Autonumbers "skip" values if you start a record and decide not.

Do a search on-line for "custom autonumbers" to find ways to roll your own
sequence number routine.

Good luck!

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
  Boon replied to Jeff Boyce
09-Feb-10 10:16 AM
Thanks Jeff. Looks like I need to redesign my database to suit my need.

One question here...  Says I have a consecutive sequence of Autonumber from
1 to 100 in my table. Then I  deleted the records with autonumber= 10 and
50.

Question
1. without compact/repair, I notice that the Autonumber continue at 101,
102,,.....
2. If I do the compact/repair, what number will the Autonumber continue at?
10, or 50, or 101?

thanks!
Boon
  Jeff Boyce replied to Boon
09-Feb-10 11:03 AM
The next highest number (not the ones "in between").

This is as it should be ... imagine if you used that autonumber as an ID in
a parent table, and a corresponding foreign key in a child table.  Add a new
child record attached to Autonumber ID=50.  Now delete the parent table
record ID=50.

You have an orphan!

Worse yet, if you re-use "50", you just gave that orphan a new "parent",
with no guarantee they are actually related!

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
  Duane Hookom replied to Boon
09-Feb-10 11:28 AM
101 but you should not really care as long as it is unique and the proper
relationships and integrity is enforced.

--
Duane Hookom
Microsoft Access MVP
Create New Account
help
AutoNumber Field Limits - NOT "How do I reset?" DataBase My questions about this are: What is the upper limit of an AutoNumber field? and are the jumps in numbering going to reduce the capacity of my table / database (already have 1000 records, anticipate several million over the course of the database's life), ultimately? (Access 2000) The numbering in one of my tables jumped from 374 useage and is now in negative numbers. I do plan to implement the "compact the database, make a new table and run an append query" method. I did want to know about the limits, still. Thank you. Access Discussions Excel (1) Database (1) Bontrager (1) Briefcase (1) Windows (1) Clashes (1 Appends (1) Useage (1) Unless there is a corruption problem, it will not reduce the number sounds like the autonumber ID field New Values property was changed to Random. Or the database was accidentally replicated or dropped in Windows Briefcase which would also change the above New updated see http: / / www.autofeupdater.com / Granite Fleet Manager http: / / www.granitefleet.com / Access effectively appends all records, then checks the unique indexes for clashes and DRI. It has to use
Speed Ferret usage DataBase I have an Access 2003 DB that has lots of issues, one of which is help is greatly appreciated! Access Discussions Access 2.0 (1) Access 2003 (1) Office (1) Database (1) AutoCorrect (1) Leszinsky (1) Windows (1) Reddick (1) I do not believe either Speed Ferret nor the competitive product, Find and Replace, www.rickworld.com, will modify a database without permissions. You need to search because there is at least one software product (free I cannot imagine any knowledgeable Access developer relying on Access security to really protect their database. . . given that it is been easily breakable since Access 2.0 days. . . but overcautious or renames fields from a model to a target (useful for copying changes from your test database to the production copy without needing to write reams of complicated DDL that creates new fields, appends the data then deletes the original field). 3. renames tables. 4. copies relationships. This allowed me to make changes to my test database on my PC, then take a copy of that and propagate all the changes to the production database in about an hour. It was a pretty extensive set of changes and writing code
Append to two different tables DataBase I think I know the answer: I want to Append "working" table fields to two passengers on the same reservation, etc.) which are associated with one tblReservation record. My FE database form for tblReservations uses a subform for tblReservationDetails so the main reservation information is presented table to another table. And a test of this process works as advertised - tblWorking.FirstName appends into Reservations.FirstName. But recent posts lead me to believe I can append one table append query work ? Thanks for you prompt response, John. Fullname IS required as my FE database consists of a frmReservations which contains FirstName, LastName, PhoneNumber, FareDue, PaymentMethod, CreditCardNo, TakenBy, and Agent. In the middle of this FE database form is frmReservationDetails subform which contains Fullname, TravelDate, Direction(North / South), PULocation, DOLocation, Time, Type I CAN NOT append to more than one table at a time. This means two appends - minimum. One to create the Reservation table record, then another append to put info into FIRST append, all bets are off. What now ? UPDATE ! I "Compacted and Repaired" the BE Database and now the Autonumber sequence is correct. I still do not know how Access is
Table field names to appear alphabetically DataBase Hi, I have just started doing queries in access on our accounting database and I would like to know is there a way I can get the tables crank out the queries automatically with all the fields included in alpha order. . . Option Compare Database Option Explicit Function ShowAllTables(Optional bShowFieldsToo As Boolean) 'Purpose: List the tables (and optionally their How to create a query 'Note: Requires a table named MyTable. Dim db As DAO.Database Dim qdf As DAO.QueryDef Dim strQueryName As String 'assuming no spaces in table name strQueryName = "qryAlpha_" & strTable Set db = CurrentDb() 'The next line creates and automatically appends the QueryDef. Set qdf = db.CreateQueryDef(strQueryName) 'Set the SQL property to a string representing appear, alphabetically description: Hi, I have just started doing queries in access on our accounting database and I would like to know is there a way I can get the tables
how to?? 10 random records per user in large file DataBase Hello, I am just starting to learn Access and know some basics. I have tried need, but obviously Access is not reading my mind correctly wko I am working with database tables that have around 200, 000 rows of data pertaining to work-units completed by Discussions Excel (1) VBA (1) CollectRandomRecords (1) LngPatientID (1) EPatientID (1) PatientID (1) DBEngine (1) Database (1) Trixie, I am sorry, but I beg to differ. IMO, this is absolutely NOT the code with hopefully liberal comments. If you want, I can e-mail you the database and maybe save you some headaches. . PieterLinden via AccessMonster.com;667633 Wrote: Trixie, beginner doing some for actually copying and pasting the code into that big window. . . <g> Option Compare Database Option Explicit '* ** ** ** ** ** * Code Begin * ** ** ** ** ** 'Code courtesy of 'Joe Foster Private Function Randomizer() As Integer Static the random set of records (the Top values query) for this record's PatientID ' and appends the records to our holding table. Debug.Print "Collecting records for " & rsP.Fields("PatientID") & ". . ." CollectRandomRecords