Results 1 to 7 of 7
  1. #1
    lizzywu is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    41

    Generate auto number like 100011,100012...


    Hi there,

    I’ve got a table in which subjectid, as the primary key, is an autonumber starting with 10001 (ending with 10100). I want to create another table with at least three different addresses for each subject. Is it possible to generate autonumber based on the way of setting up subjectid? Say, I’d like to have addressid to be
    100011
    100012
    100013
    100021
    100022
    100023
    ...
    101001
    101002
    101003
    Thank you very much!

  2. #2
    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,847
    Autonumbers are NOT NECESSARILY incremental/in sequence. Autonumbers are intended for use by Access and are considered to be UNIQUE. If you need sequential numbers, and contiguous numbers, then autonumber is NOT the choice.

    Autonumbers can be set up to start at a certain value, but they are NOT sequential necessarily.

  3. #3
    lizzywu is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    41
    You're right, Orange.
    Do you know how to generate such sequential numbers? Thank you.

  4. #4
    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,847

  5. #5
    lizzywu is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    41
    Is it possible to do that without using a form?

  6. #6
    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,847
    Yes, you can do it with vba.
    NextSubjectId = DMax("SubjectID","YourTableName") + 1

    Part of this method is to store the new Value in the table, then the next time you need a to increment SubjectId, you use the DMax("SubjectID","YourTableName") + 1

    The way this works you assign the first SubjectId to a record in your Table.
    Then Dmax says get me the Max value of SubjectId in "YourTablename" and add 1 to it. That's the number to store with the next record. Once it is stored, and you want to add a new record, you use the
    DMax("SubjectID","YourTableName") + 1 to get the next number and so on and so on.

  7. #7
    Join Date
    May 2010
    Posts
    339
    What happens if the database is split, and two or three users are needing sequential numbers on unsaved records?

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

Similar Threads

  1. Replies: 1
    Last Post: 07-26-2011, 06:10 AM
  2. Auto generate reference number
    By JonB1 in forum Import/Export Data
    Replies: 1
    Last Post: 02-19-2011, 06:38 AM
  3. AuTo NuMbEr
    By Evgeny in forum Forms
    Replies: 2
    Last Post: 04-25-2010, 04:23 AM
  4. Auto Generate Record
    By mjhopler in forum Forms
    Replies: 2
    Last Post: 02-10-2010, 03:40 PM
  5. Replies: 1
    Last Post: 10-01-2009, 06:41 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