|
-
Sep 3rd, 2004, 11:25 AM
#1
Thread Starter
Lively Member
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
-
Sep 3rd, 2004, 11:49 AM
#2
Try this statement
Code:
strSQL = "SELECT * FROM SurveyQuestionnaire_SurveyID
ORDER BY Qst_Number, Format(Qst_Subitem,'@@')"
-
Sep 3rd, 2004, 01:15 PM
#3
Thread Starter
Lively Member
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!
-
Sep 3rd, 2004, 01:48 PM
#4
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Sep 3rd, 2004, 02:06 PM
#5
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"
-
Sep 3rd, 2004, 05:32 PM
#6
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|