Results 1 to 9 of 9
  1. #1
    treehstn is offline Novice
    Windows 10 Office 365
    Join Date
    Apr 2022
    Posts
    2

    How to use autonumber properly

    Hi,



    I have a db that I use to make inventory tags for selling items in my antique booth. I've used it for years but have had to manually key every item number into the db. I'd like it to sequentially autonumber my inventory. Right now I'm using a field I've named "InventoryNumber". I have nearly 2000 rows in my main table and a few dozen in another table. It's not a lot of data. Is there a way that I can either change the InventoryNumber field from ShortText to autonumber and have the existing numbers stay the same? Or should I add a field to the db that is the autonumber?

    The above table is using straight numeric digits for the inventory number. But in my jewelry table I'm using J-1140 as the inventory number. I would like to do the same in this table with the autonumbering...

    Thank you for your help!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    In a brief test, I'm not allowed to change an existing field to autonumber. You can certainly add a new field.

    For the table that has J-1140, you can use an autonumber field for the numeric part and a text field for the letter, and concatenate them for the user.

    Note that some people will have an issue with you using an autonumber field for a user-visible value. I don't, as long as you understand its limitations. For example, in certain situations it can skip a number.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    treehstn is offline Novice
    Windows 10 Office 365
    Join Date
    Apr 2022
    Posts
    2
    I tried adding a new field and it lets me do that but the autonumber starts at 1. From what I'm reading if I need it to start at my first existing inventory number, which is 1064, then I have to run some kind of a query to get it to do that. I don't know how to do queries or VB. I'm still fumbling around trying to figure it out....

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Create a new empty table based on you existing table. Add the auto number field.

    Then create an insert query to populate the new table from the old table, assigning your inventory number field to the auto number field

  6. #6
    Join Date
    Apr 2017
    Posts
    1,680
    For start, let's set the terminology straight!
    Autonumber in access (and in other relational databases) is specific numeric field with unique values, which database fills automatically (without any input from user, or through code) whenever a new record is created.
    What you want, is an unique identifier for entry in your table. Generally such identifier is created in BeforeUpdate event of form. (It is possible also to have a hidden control linked to this identifier on form, which is filled automatically whenever a new entry in form is created, and saved when the record is saved, but this approach may cause problems when several users are adding new records at nearly same time.). NB! You can define an unique index based on this field - additional to Primary Key of table.

    From post#1 follows, you want an identifier in format "C-####", where "C" is (single?) character, and "####" is a number.
    Obviously character may have other values than "J" in your example (otherwise you could use a numeric identifier or autonumber instead). So you have to determine the character value somehow (based on some fields in entry following some set of rules, or by manual entry, or on whatever);
    The next step is to find latest identifier with same character part in your table. To make this possible, you must have the numeric part of fixed width (i.e. your identifiers must be like "J-0001", J-0001", etc., up to "J-9999". NB! You must determine the width of numeric part wide enough so you don't need to redesign the field anytime later, or you'll get into world of hurt's!). When the numeric part is of fixed width, the latest identifier can be easily found using a query like "SELECT TOP 1 YourIdentifier FROM YourTable WHERE Left(YourIdentifier,1) = 'J' ORDER BY YourIdentifier DESC". From found value, you remove character part and "-", and convert remaining part to integer;
    The last step is to add 1 to found integer, composite new identifier from character part and new number, and use the value you got as identifier field value of entry to be saved.

  7. #7
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    There used to be a page in "UtterAccess" about Autonumbers, but they redesigned their site and it disappeared. However, I did find a copy I saved on my computer.


    Autonumbers--What they are NOT and What They Are


    It is 4 pages long and rather than paste it in the reply, I'm going to attach it. (it is RTF format)
    Attached Files Attached Files

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Steve, want to borrow my link?
    http://access.mvps.org/access/general/gen0025.htm
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    @Micron, Thanks......I've got that one.
    The UtterAccess link had much more about Autonumbers:

    A Small excerpt ....

    What they are NOT:
    1. Row (record) sequence numbers.
    2. An "order of entry into the table" number
    3. A "gapless" series of numbers.
    4. Editable numbers.
    .
    .
    .
    .



    Actually, I have 4 links about Autonumbers: (well, 3 now that the UtterAccess link is broken )
    Autonumbers--What they are NOT and What They Are........................(link broken)
    Microsoft Access Tables: Primary Key Tips and Techniques........... http://www.fmsinc.com/free/newtips/primarykey.asp
    Use Autonumbers properly.................................................. ......... http://access.mvps.org/access/general/gen0025.htm
    Relational Database Primary Keys................................................. http://www.databasedev.co.uk/primary_keys.html

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

Similar Threads

  1. Not Counting Properly in VBA
    By Isebrand in forum Access
    Replies: 3
    Last Post: 01-19-2019, 12:45 PM
  2. Replies: 7
    Last Post: 08-28-2017, 02:50 PM
  3. VBA Not Iterating Properly
    By jo15765 in forum Programming
    Replies: 7
    Last Post: 03-30-2017, 04:56 PM
  4. Is this relationship set up properly
    By Xterra14s in forum Access
    Replies: 1
    Last Post: 07-20-2016, 06:19 AM
  5. Replies: 4
    Last Post: 11-21-2013, 05:06 PM

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