Access 2007-2019
Access 2000-2003
Access Seminars
TechHelp Support
Tips & Tricks
Access Forum
Course Index
Topic Glossary
Insider Circle
 
Home   Courses   Seminars   Templates   Help   TechHelp   Forums   Contact   Join   Order   Logon  
 
 
Access: Interesting Sort Problem
By Richard Rost   Richard Rost on Twitter Richard Rost on LinkedIn Email Richard Rost   13 years ago

Q: I read your Q&A regarding sorting text fields that have fields that contain numbers and letters. I have fields where most contain only currency and other fields are only letters. (i.e. $1,590,000 or "Asset Sale"). How would I sort them so the currency fields are at the top of the report showing HIGHEST sales first, and the Asset Sales appear at the end of the report?

A: Assuming the field type is TEXT, your values should automatically sort so that the currency values are at the top of the list, but they'll be in ASCENDING (low to high) order. Those are the rules of an Alphanumeric sort.

To do what you want, you'll have to play a query shell game. In a nutshell (no pun intended), you could create a CALCULATED QUERY FIELD called SortField.

/tips/access/calculated-query-fields

The SortField could be the value of your numeric/currency value subtracted from some outrageously large number (something bigger than any of your data values):

SortField: IIf(IsNumeric([MyValue]),1000000000-[MyValue],[MyValue])

You'll have to use the IIF and IsNumeric functions so that you're not trying to subtract a text value, which will give you an error:

/tips/access/iif-function

Now you'll have a column of numbers and text, but the numbers will be in reverse order, because when you subtract from a bigger number, you get the difference. So if my original list is:

$145
$220
black
white
gold
$356
$2


When I run the query, I get:

999999855
999999780
black
white
gold
999999644
999999998


Now if you SORT by this SortField in your query, you will get:

$356 999999644
$220, 999999780
$145, 999999855
$2, 999999998
black, black
gold, gold
white, white


Notice that the first column is sorted exactly as you wanted.

Start a NEW Conversation
 
Only students may post right now. Click here for more information on how you can set up an account. If you are a student, please LOG ON first.
 
Subscribe
 

You may want to read these articles from the 599CD News:

5/9/2021Access D29 Started
5/9/2021Access Developer 30
5/9/2021Access Developer 30 Lessons
5/9/2021Access Developer 30
5/8/2021Data Entry
5/2/2021Split Commissions
4/30/2021Close Form
4/30/2021Close All Forms
4/29/2021Quick Queries #3
4/26/2021Combining Names
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Account Login
Online Theater
Downloads
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Email Richard
Mailing Address
Phone Number
Fax Number
Course Survey
Blog RSS Feed    Twitter

YouTube Channel    LinkedIn
Keywords: access sort iif isnumeric query  PermaLink