Results 1 to 4 of 4
  1. #1
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    348

    Changing Order By

    My field can contain both numbers and strings (like A1, B2, C3). I can't easily change this.

    I was using Order By on this field, but of course if numbers then 11 comes before 2 etc. Using Val fixes that but mucks up the alphanumeric ones.



    Possibly I could check the field first, then use the order by depending on whether Strings or Numbers (There is never both). But is there a better way ?

  2. #2
    Join Date
    Apr 2017
    Posts
    1,679
    Either split this field to 2 (one field for string part, and second field for numeric part), or make the field to have a fixed length for numeric part, using leading zeros (like "A001", "B002", "C003" or "X999").

  3. #3
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    348
    Thanks for the reply. I'm a bit restrained in what changes I can make. Ended up with
    Code:
     rx.FindFirst ("ATrack= '" & "11'")
     If rx.NoMatch = False Then myQuery.sql = Replace(myQuery.sql, "ATrack", "Val([ATrack])")
    And doing some testing to see if that's enough.

  4. #4
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,043
    create a calculated, numeric field in the query: if the original field is numeric, then take the numeric value, else 9999999999999999999 or something like that. Then create the sort order on 2 fields: first on calculated field, second on original field.

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

Similar Threads

  1. Replies: 8
    Last Post: 09-18-2015, 01:52 PM
  2. Replies: 5
    Last Post: 01-20-2015, 02:04 PM
  3. Replies: 8
    Last Post: 05-16-2014, 12:12 PM
  4. Changing order by using code
    By FRAZ in forum Queries
    Replies: 4
    Last Post: 01-22-2014, 12:54 PM
  5. Replies: 7
    Last Post: 10-03-2011, 12:44 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