Results 1 to 6 of 6
  1. #1
    RustyRick is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2016
    Location
    NW Alberta
    Posts
    53

    sort key or ID

    How do I get a field to sort right:


    M1
    M2
    M3

    Instead of
    M1
    M10
    M2

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    If always starts with M add a field to the query SortOn:cLng(Replace([id],"M","")) or SortOn:cLng(Mid([id],2))and sort on that instead.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    RustyRick is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2016
    Location
    NW Alberta
    Posts
    53
    Sorry it's not a Query. it is a list in a table.

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    A table is a list....
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,979
    For info, as its a text field, it is sorting correctly already, but alphabetically.
    If all records start with M, another method of doing this is to use a number field but format it for display purposes with a leading M. That will sort the way you want
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    or modify the number part when created so they are all the same length

    M01
    M10
    M02

    if your number part is expected to reach 3 digits then you would need

    M001
    M010
    M002


    when you create your code to add the preceding zeros you would use something like

    "M" & format(num,"00")

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

Similar Threads

  1. Replies: 1
    Last Post: 04-07-2014, 02:59 AM
  2. sort filter, doesn't sort everything
    By deso in forum Queries
    Replies: 4
    Last Post: 01-25-2013, 05:27 AM
  3. Invalid Sort
    By DBA-Meister in forum Access
    Replies: 5
    Last Post: 10-04-2012, 01:37 PM
  4. How to sort by three sort orders
    By captgnvr in forum Access
    Replies: 4
    Last Post: 11-09-2009, 07:30 AM
  5. Sort
    By mmp97 in forum Access
    Replies: 1
    Last Post: 12-18-2008, 10:14 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