Results 1 to 8 of 8
  1. #1
    Chronus13 is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2020
    Posts
    24

    Incorrect sort order


    Hello everyone. First, i am trying to sort a column that is alpha numeric. Examples look like this: A-1,A-2,A-3,A-4,A-10,A-11. In my tables I don't really care how they look because they are Primary Keyed by a different number that never is shown outside the table. I use that table and made a query, still here the sort does not matter. I then create a report that has these in a column and it always sorts A-1,A-10,A-11,A-2,A-3,A-4. From what I have found on the internet is there is no way to actually make this work unless I create ALOT of code. I am hoping there is an easier way. Any ideas?

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    No, just split the alpha from numeric and sort alpha, then numeric.
    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
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    In extra column convert it to a number:
    Cint(mid([field], instr([field],"-")+1))

    then sort

  4. #4
    Chronus13 is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2020
    Posts
    24
    OK, I am sure I probably just don't see why it isn't working. I took the locations..A-1, A-2 and the rest and split them up into two separate columns (Drawer-A) and (Item-1, 2, 3 etc.) and the numbers are still sorting incorrectly putting the 10 before the 2 for example.

  5. #5
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Because your field data type is text and not a number data type? This happens when the numbers are text because anything that starts with 1 comes before that which starts with 2. So
    1
    11
    111
    2
    21
    etc.
    If you did this in a query, you'll have to coerce the data type as was stated in post 3.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    So surround the numeric field with Val() as it sounds like it is still text?
    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

  7. #7
    Chronus13 is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2020
    Posts
    24
    OMG! I forgot to change it to a number in design view lol. Thanks!

  8. #8
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    As I stated in other threads, val stops reading a string as soon as it encounters a character than it cannot recognize as a number or a character that pertains to numbers, such as the decimal separator. However, commas as separators are not recognized. Anyway, Val(A-1) will return zero in a query where the field contains A-1.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Order by - multiple sort
    By carmenv323 in forum Queries
    Replies: 1
    Last Post: 01-18-2022, 10:25 AM
  2. ORDER BY sort order?
    By TOPSie in forum Queries
    Replies: 4
    Last Post: 04-23-2021, 03:25 AM
  3. Replies: 5
    Last Post: 08-27-2019, 08:41 AM
  4. Incorrect alpha sort on report & query
    By Dano in forum Reports
    Replies: 9
    Last Post: 12-14-2016, 08:57 AM
  5. Incorrect syntax near keyword “ORDER"
    By k9drh in forum Import/Export Data
    Replies: 1
    Last Post: 06-13-2011, 07:36 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