Results 1 to 6 of 6

Thread: Sorting text "properly"

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    78

    Sorting text "properly"

    Good afternoon and TGIF!!

    I have a database program that supports a survey process. I need to be able to sort questions by question number and subitem, for instance 1a, 1b, 1 c, etc.

    I have the question number in a field and the subitem in another
    Qst_Number, Qst_Subitem

    This works great until they go over 26 subitems and start using "aa", "bb", "cc", and so on.

    When I sort the records by Qst_Number, Qst_Subitem I get
    a
    aa
    b
    bb
    c
    cc
    etc.


    I need a through z, then aa through zz

    I use the sort when I send the data to Word for reports. Using an ADO recordset of data pulled from an Access Table.

    "SELECT * FROM SurveyQuestionnaire_SurveyID ORDER BY Qst_Number, Qst_Subitem"

    Any suggestions??

    Thanks,
    Mary

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Try this statement


    Code:
    strSQL = "SELECT * FROM SurveyQuestionnaire_SurveyID 
    ORDER BY Qst_Number, Format(Qst_Subitem,'@@')"

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    78
    God Bless you Bruce!!!!

    Thanks so much that did the trick!!!! It also worked in the data entry screens as well when I pulled up the recordsets then!!!

    Have a great holiday!

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Brucevde, why would "z " be sorted before "aa", resulting in "a " - "z "
    and then "aa" - "zz"? I understant that the @@ places a space
    from right to left when there is not enough characters to format
    the string. Shouldn't it go "a " and then "aa"?


    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    As you mentioned, format fills Right to Left and the @ symbol reserves a space. Formatting a single letter results in " a" and not "a ". Since the space character comes first in the sort order we get the desired affect of

    " a"
    " b"
    " z"
    "aa"
    "ab"
    "az"
    "ba"
    "bz"
    "zz"

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Ok, got it now.

    Thanks.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width