Results 1 to 3 of 3
  1. #1
    Andre73 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Feb 2015
    Posts
    1

    auto generate a 5 digit number?

    Hi guys, I'm just trying to create my first database for a friend to use in with an existing system. One thing it needs to do is create a 5 digit number that is unique. I've found the autonumber thing and also primary key thing but that starts at '1' - I need it to start either at 00001 or even 12345 - it doesn't matter as long as it has 5 numbers that no other record has, it just needs 5 digits to fit in with their other system which eventually it will pass information to.

  2. #2
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    This question comes up regularly. You are making work for yourself and should reconsider whether it is worth the effort. A database provides autonumber which is your easy out-of-the-box increment-er. It is a number and in a database a number can never have leading 0s. Only a text field can have leading 0s - and it is far more challenging to set up any sort of auto increment of a text value.

    In your case you have the additional dilemma of auto incrementing beyond 5 digit i.e. what is to happen after 99999? ... So the first advice is abandon the idea and preconceptions and accept autonumber.

    Having said all that: the general outline for something like this is to use autonumber to generate a value then copy that value into a text box, count its digits, and stuff 0s as necessary in a string concantenation.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    see http://allenbrowne.com/ser-26.html for more info.
    Hopefully, getting a 5 digit number is not the heart of your proposed database.
    You should determine what this number will be used for? What happens if there are gaps in the numbers?
    You have not given any info regarding the business and/or business rules/facts of the proposed database and the existing database into which records from your proposed database will interact/fit.

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

Similar Threads

  1. Replies: 1
    Last Post: 01-11-2012, 03:07 PM
  2. Generate auto number like 100011,100012...
    By lizzywu in forum Access
    Replies: 6
    Last Post: 11-12-2011, 01:43 PM
  3. Access 2007: Can't Display 17 Digit Number
    By HedgeHog in forum Access
    Replies: 9
    Last Post: 08-14-2011, 01:46 PM
  4. Replies: 1
    Last Post: 07-26-2011, 06:10 AM
  5. Auto generate reference number
    By JonB1 in forum Import/Export Data
    Replies: 1
    Last Post: 02-19-2011, 06:38 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