Results 1 to 7 of 7
  1. #1
    warrenpage is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2013
    Posts
    69

    Sorting in Proper Numerical Order, not 1, 10, 11, 12, 2, 20, 21, etc.?

    Hello everyone. I need help sorting a query and/or a report. I’m using Access 2013.



    I have a movie collection database, and I want to create a query and a report for two of its fields. The fields are called DVDColor and DVDNumber.

    The DVDColor field has records such as Blue, Green, Red, White, and Yellow.

    The DVDNumber field is self-explanatory, going from 1 to 50 or more.

    I created a query with DVDColor as the first field, and DVDNumber as the second field.

    I ran the query, then sorted it, selecting DVDColor as the first field, and DVDNumber as the second field. So far, pretty routine.
    The problem is minor but annoying: The sort created a list that was not in actual numerical order. Here’s what I see:

    Blue 1
    Blue 10
    Blue 11
    Blue 12
    Blue 2
    Blue 20
    Blue 21
    Green 1
    Green 10
    Green 11

    And so on.

    I did the same thing with a report, and the results were the same.

    Is there a way to sort a list such as this so the numbers are in actual numerical order? If so, what’s the simplest procedure? Would it be simpler for me to replace the single-digit numbers such as 1, 2, 3, with 01, 02, 03? If that’s the easiest solution, how can I do that without it affecting numbers with two or three digits? Thank you! Warren Page

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    You have sorted by a text field, not a number.
    You could try -- in a query--- (untested)

    SELECT
    DVDColor
    ,DVDNumbver
    FROM
    "THeDVD TABLEName goes here'
    Order BY
    DVDColor
    , Int(DVDNumber);

  3. #3
    warrenpage is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2013
    Posts
    69
    Thank you for replying.

    I tried your SQL code (removed the typo from DVDNumbver) and inserted the dvd table name but the code did not work.

    Is there a way to convert the numerical text to actual numbers? Can I redesign the field while there is already data in it?

    I also need to remove the NULL values. I know how to do that: Add WHERE NOT DVDColor is Null. But I'm not sure where to put it in your code.

    Lastly, I see commas at the beginning of the third and final lines in your code. I just want to double check and make sure that is correct.

    Here is the code I tried, which did not work:

    SELECT
    DVDColor
    ,DVDNumber
    WHERE NOT DVDColor is Null
    FROM
    tblMovies
    Order BY
    DVDColor
    , Int(DVDNumber)

    Notice I left off the semi colon at the end.
    What in this code needs to be changed?

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    You would have to change the datatype of that text field in the Table (to Number or Integer).
    The method I showed should only change it for sorting.

    The commas just separate values.

  5. #5
    warrenpage is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2013
    Posts
    69
    "You would have to change the datatype of that text field in the Table (to Number or Integer)."

    Can that be done with data already entered in the table?

    And what is wrong with the SQL code?

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Where clause in wrong position

    SELECT
    DVDColor
    ,DVDNumber

    FROM
    tblMovies

    WHERE NOT DVDColor is Null

    Order BY
    DVDColor
    , Int(DVDNumber)



    Since this is only a read query and nothing will change --try it and see if it's what you need.
    As I said it is untested.

  7. #7
    warrenpage is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2013
    Posts
    69
    Ahh okay. Thank you. I went ahead and changed the numbers from short text to numbers and the sort worked correctly. I can always change the format back if it causes problems in the future. I tried it on a backup so that the main db won't be affected.

    The sort also works well when I filter the form. Thanks for your help. WP

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

Similar Threads

  1. Replies: 4
    Last Post: 09-09-2013, 11:37 AM
  2. Replies: 2
    Last Post: 07-30-2013, 02:24 PM
  3. Sorting Order query
    By drunkenneo in forum Queries
    Replies: 1
    Last Post: 06-24-2013, 06:54 AM
  4. Clueless- numerical order
    By Andy_Aus in forum Access
    Replies: 1
    Last Post: 11-28-2011, 08:49 AM
  5. Sorting a form's records in order by date.
    By slikbaz in forum Access
    Replies: 3
    Last Post: 11-20-2010, 01:11 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