Results 1 to 7 of 7
  1. #1
    jinz is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    13

    primary key autonumbers problem

    My autonumbers are not in order for tables.



    As in for example

    for a customer


    customerid customer first name customer last name

    17 john parker
    18 james johnson
    19 alex scott


    this is right at the top of the table the first sets of data,

    i want it to be

    customerid
    1
    2
    3
    4
    5
    ,etc

    Why does it have a random number like "17" when I DO NOT have the first 17 customers !

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    AutoNumber does not automatically reseed itself back to 1. So if you import 16 records (originally usually assigned 1-16), but then delete them and re-import, it will start up at 17.
    Likewise, if you delete random records here and there, you will have "gaps" in your Autonumber. It shouldn't really matter though. The only thing Autonumber should really be used for is to guarantee a unique number (you should NOT try to get the record count for a table by looking at the largest value of Autonumber!). You can use DCOUNT or an Aggregate Query to count your table records.

    Note, if you delete all the records from a table, you can "reset" Autonumber to 1 by running a "Compact and Repair" on your database.
    If you have existing data that you do not want to delete, but want to reset the Autonumber to start at 1, one way is to delete the Autonumber field, then add a new Autonumber field to your table.

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You do not want an AutoNumber in this case. The AutoNumber field is not designed as a user-visible field. The main problems are:

    * You are not going to be able to guarantee the number remains sequential or even positive.
    * You can not change the number.
    * You can not "re-start" or skip numbers

    The point is an AutoNumber is intended to be an AutoNumber, not a SequentialNumber. It's intended to provide a system-visible unique record identifier, not a user-visible one. It's so close it really makes you want to use an AutoNumber, but it's not close enough.


    The AutoNumber Data Type
    ---------------------------
    The AutoNumber data type stores an integer that Microsoft Access increments (adds to) automatically as you add new records. You can use the AutoNumber data type as a unique record identification for tables having no other unique value. But the uses should never see the number.


    Read: http://www.applecore99.com/tbl/tbl012.asp



    PS: Also see:http://access.mvps.org/access/tencommandments.htm Shouldn't use spaces in names

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    PS: Also see:http://access.mvps.org/access/tencommandments.htm Shouldn't use spaces in names
    Great link! I bookmarked it. I am always telling people not to use spaces in their names - now I have backup. Lots of other good tidbits to pass along to newbies.

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Also note the link to the use of "Lookup Fields"

    The Access Web is one of most used reference sites>>>> http://access.mvps.org/access/

  6. #6
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Also note the link to the use of "Lookup Fields"
    Yeah, I probably have been guilty of that one from time-to-time. I do use them on occassion, but pretty sparingly.

    I used to frequent that site years ago, but not as much recently. I agree, they do have a lot of good stuff on it.

  7. #7
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 03-16-2012, 01:07 PM
  2. Problem with primary key on imported database
    By 1953hogan in forum Access
    Replies: 1
    Last Post: 06-23-2011, 05:02 PM
  3. Fixing Negative Autonumbers
    By prophecym in forum Access
    Replies: 5
    Last Post: 02-03-2011, 03:48 PM
  4. AutoNumbers
    By remmons in forum Access
    Replies: 1
    Last Post: 01-30-2010, 01:39 PM
  5. Are text primary keys less efficient than autonumbers?
    By bar tomas in forum Database Design
    Replies: 4
    Last Post: 05-11-2009, 09:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums