Results 1 to 5 of 5
  1. #1
    HansBades is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2021
    Posts
    85

    Number items with a query

    I have a query that produces a list of SKUs based on certain criteria. How can I add a field in the query to each SKU to number the list in numerical order. For instance, if the query returns



    SKU
    Yhlo23
    Thj23
    Whj24


    How can I get it to number the SKUs based on the results of the query as such?

    SKU Order
    Yhlo23 1
    Thj23 2
    Whj24 3


    Thank you!

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,558
    I have Google on this laptop.
    This is what it produced on a simple search?

    https://www.google.com/search?q=incr...hrome&ie=UTF-8
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    I have a table with several animals.
    This query selects those animals whose name begins with "G" and adds a sequential index number.
    AName is the animal name and animalId is the autonumber PK. You may be able to adapt this to your situation.

    Code:
    SELECT t.aname, (SELECT COUNT(*)
            FROM Animal AS x
            WHERE x.animalid <= t.animalid
    and (((Left([aname],1))="G"))
                            ) AS RowNumber
    FROM animal AS t
    where (((Left([aname],1))="G"))
    ORDER BY t.aname;
    Result:

    aname RowNumber
    Geronimo 1
    GIVPOL 2
    GRVYNU 3
    Last edited by orange; 07-01-2022 at 11:38 AM. Reason: grammar

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    HansBades is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2021
    Posts
    85
    Thank you. I tried that and for the most part it worked but there were always two skus (the same ones) that were in the wrong place every time I ran it. I will figure this out at another time. I am surprised access doesn't have a built in way to do this. Thanks for the tip.

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

Similar Threads

  1. List number items in parameter prompt for a Query
    By Kshugerts003 in forum Access
    Replies: 2
    Last Post: 10-07-2019, 08:06 AM
  2. limit number of selected items in listbox
    By rwahdan@gmail.com in forum Access
    Replies: 4
    Last Post: 01-28-2018, 01:35 AM
  3. Replies: 15
    Last Post: 10-08-2015, 03:33 PM
  4. Calculating number of items based on dropdown
    By arstueck in forum Queries
    Replies: 3
    Last Post: 06-14-2014, 01:51 PM
  5. Replies: 2
    Last Post: 05-21-2014, 06:16 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