Results 1 to 8 of 8
  1. #1
    MsAxes is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    100

    How to assign a number to each unique result?

    I have a table with names. That table sometimes has duplicates and names drop or are added depending on the month. I would like to have a table that has the unique names with a number assigned to them starting with 1. I created query1 that appends to Names_IDs table which has a NamesC field with an auto-number assigned to each unique name. It works great except each time I run it, the auto-number starts from the number it left off. I just need it to reset back to 1 and it doesn't matter who has what number assigned.



    Any ideas of how to have those numbers start with 1 each time the query is ran?
    Attached Files Attached Files

  2. #2
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    If you don't care that Mike is #2 today and #4 next time, don't bother with an autonumber, which should never be used as meaningful data - only to uniquely identify a record.
    Search on 'ms access sql generate sequential numbers' and you'll get some hits. Some will be as simple as generating numbers, some will offer grouping. Pick one that applies to you.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    MsAxes is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    100
    Thank you - the statement below is what I used. This works perfectly when your sequential number is based on a text field.



    Code:
    SELECT     (Select Count(1) FROM Names_IDs as A        WHERE A.Names <=Names_IDs.Names) AS Sequence,
        Names_IDs.Names
    FROM Names_IDs
    ORDER BY Names_IDs.Names;
    Credit to:

    http://rogersaccessblog.blogspot.com...in-access.html

  4. #4
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Never mind, OP found solution above.

  5. #5
    MsAxes is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    100
    I’d still like to read your suggestion

  6. #6
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Quote Originally Posted by MsAxes View Post
    I’d still like to read your suggestion
    OK, I added a RunCode to the end of Macro1, and added a code module to hold function fcnCount()

    Here's the DB

    MsAxes-davegri-v01.zip

  7. #7
    MsAxes is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Posts
    100
    This is a great alternative - thanks for sharing.

  8. #8
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Quote Originally Posted by MsAxes View Post
    This is a great alternative - thanks for sharing.
    Happy you like it, and thanks for the star!

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

Similar Threads

  1. Assign unique identier
    By dslaugh in forum Access
    Replies: 5
    Last Post: 08-12-2019, 12:59 PM
  2. Replies: 2
    Last Post: 10-12-2016, 05:48 PM
  3. Replies: 2
    Last Post: 08-11-2015, 01:47 AM
  4. Looping(?) to get Unique Result
    By tonere in forum Programming
    Replies: 3
    Last Post: 11-15-2011, 07:40 AM
  5. Assign Unique IDs to Multiple Tags
    By willbmisled in forum Queries
    Replies: 1
    Last Post: 02-02-2011, 10:11 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