Results 1 to 8 of 8
  1. #1
    kazaccess is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jul 2013
    Posts
    43

    Ordering Numeric Values

    I currently have records that end with a letter and 2 numbers. For example, A1, A2, ... , A10, A11. When I try to sort my table/query by these values, A10 & A11 come before A2. It seems that it is sorting by the first digit shown. Is there any way to fix this quickly within table/query properties so that this can be displayed in proper numeric order?

  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 could try (untested) sorting by Val(yourFieldName). You are getting an alpha sort at the moment.

  3. #3
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    It is sorting as text field and not number.

    To fix it, you have to build a query with just the number portion of the text field. As long as they are consistent (start with letter follow by numbers). This query should fix the issue.

    SELECT TABLENAME.SORTFIELDNAME, ...., MID(TABLENAME.SORTFIELDNAME, 2, LEN(TABLENAME.SORTFIELDNAME))
    FROM TABLENAME
    ORDER BY MID(TABLENAME.SORTFIELDNAME, 2, LEN(TABLENAME.SORTFIELDNAME))

  4. #4
    kazaccess is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jul 2013
    Posts
    43
    Inserting that "order by" statement is giving me the same results. A10-19 are being displayed before A2.
    I'm sorry, I should have included this is my description: the full length of these values is the first 2 letters of the day of the week + number. So, for Mondays, this looks like "MoA1", "MoA2", ... , "MoA10", "MoA11"

  5. #5
    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
    Try along this template --- adjust for your fields and starting position.

    SELECT Departments.Departmentname, Val(Mid([departmentName],5))
    FROM Departments
    Order By Val(Mid([departmentName],5))

  6. #6
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    Sorry forgot to convert them to numbers and it is the 3rd pisition instead of the second. Since you have 2 characters follow by numbers.

    SELECT TABLENAME.SORTFIELDNAME, ...., VAL(MID(TABLENAME.SORTFIELDNAME, 3, LEN(TABLENAME.SORTFIELDNAME)))
    FROM TABLENAME
    ORDER BY VAL(MID(TABLENAME.SORTFIELDNAME, 3, LEN(TABLENAME.SORTFIELDNAME)))

  7. #7
    kazaccess is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jul 2013
    Posts
    43
    So far, ordering by "MID(TABLENAME.SORTFIELDNAME, 3, LEN(TABLENAME.SORTFIELDNAME))" is getting me the closest to my solution. This gives me "MoA1, MoA10, MoA11, MoA2",etc.

    Using VAL() is causing my list to be "MoA5", "MoA9", "MoA8", ... , "MoA3", "MoA10", "MoA11", "MoA2", "MoA1"

    Is there some step I may be missing in doing this?

  8. #8
    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

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

Similar Threads

  1. Only show numeric values
    By dr4ke in forum Queries
    Replies: 2
    Last Post: 07-22-2012, 05:09 AM
  2. Setting Up DB with numeric values
    By dashingirish in forum Access
    Replies: 4
    Last Post: 02-17-2012, 03:41 PM
  3. Importing numeric fields with null values from XML
    By hcorvallis in forum Import/Export Data
    Replies: 1
    Last Post: 10-20-2011, 08:09 AM
  4. Updating Numeric Values
    By dssrun in forum Queries
    Replies: 9
    Last Post: 11-24-2010, 11:20 AM
  5. Replies: 5
    Last Post: 06-30-2009, 09:30 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