Results 1 to 4 of 4
  1. #1
    euphonium01 is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    40

    Numbering Records

    I'm certain the question of numbering records is an old topic, but I think my numbering issue could be a little different as records are Alpha / Numeric records. Records are not Unique but (although necessary) duplicates are rare?



    I have a field that identifies a particular widget and its location, say DA52-1. This tells me it is loctaed in Isle 'D', on shelf 'A', and the widget is a type 52-1. The next widget may not be perfectly sequential for instance, it could be DA51-3 then DA52-4 etc. The problem is DA52-11 will display before DA52-2 or DA52-5.

    I need to sort the records so that this field is how we would read it or write it in order, DA52-1, DA52-2 through to DA52-9, then DA52-10 -11 -12 and so on. DA is not always prevelant, it could be EM5-1, but again, EM5-10 will display before ID EM5-2. All records have the widget ID consisting letters first, followed by number(s), a dash, then number(s).

    Is there a way I can correct this at the Table level, or is a Query required? Or another way?

    I am OK with vba if that is required s'long as it's not too complicated Putting records in the correct order and then adding an Autonumber field to maintain that order isn't the answer for my particular needs.
    Paul

  2. #2
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,425
    I don't see any other way but to split the prefix text field (DA) from the suffix numeric field and group and sort by prefix and sort by number. What you're experiencing is what happens when you sort numbers as text data type. You can run an update query to split existing data into 2 new table fields but I'll bet this causes some kind of cascading re-designs. Then try something like

    Code:
    SELECT tblSorting.Prefix, tblSorting.Num
    FROM tblSorting
    GROUP BY tblSorting.Prefix, tblSorting.Num
    ORDER BY tblSorting.Prefix, tblSorting.Num;
    You'll get this
    Prefix Num
    DA 1
    DA 2
    DA 5
    DA 11
    DA 55
    DA 111
    EM 2
    EM 3
    EM 11
    EM 22

    You concatenate a string that you want to see in your form or query: [Prefix] & "-" & [Num]
    Could also do it in the sql that I posted. This will also make it MUCH easier to figure out the next num for a prefix should that be something you want to do.
    Last edited by Micron; 10-28-2022 at 06:57 PM. Reason: added info
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    Could you not just split at the -?
    So
    DA52 and 11
    DA52 and 2
    EM5 and 11
    EM5 and 2

    Try that, but see where DA5 and 11 comes into the mix

    Most times, that data would be split anyway, so that you have fields called Isle, Shel and WidgetType.
    Then you would combine to get what you are used to seeing. Easier to combine, than to split normally.
    Though you could create a dedicated function for the split.?
    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

  4. #4
    Join Date
    Apr 2017
    Posts
    1,792
    To make ordering by such text fields possible, instead 'DA52-1','DA52-5','DA52-10','DA52-111', etc. use someting like 'DA52-001','DA52-005','DA52-010','DA52-111' , etc.. The number of leading zeros must be do the length of this character group will be same for all records.

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

Similar Threads

  1. Counting and Numbering Records in a Query
    By Phil-AND in forum Queries
    Replies: 6
    Last Post: 03-03-2015, 01:01 PM
  2. Numbering Records
    By George in forum Access
    Replies: 6
    Last Post: 10-21-2013, 04:42 AM
  3. Auto numbering of new records
    By edwardcga in forum Forms
    Replies: 1
    Last Post: 10-20-2013, 04:19 PM
  4. Update query for numbering the records
    By kumar.dkr in forum Queries
    Replies: 4
    Last Post: 11-24-2010, 06:06 AM
  5. Numbering records
    By knightjp in forum Database Design
    Replies: 0
    Last Post: 08-17-2008, 07:07 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