Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Access 2016 - Sort order on report from query

Posted on 2016-09-20
17
Medium Priority
?
129 Views
Last Modified: 2016-09-28
Greetings!

I have a report tied to a query that has the "Record Date" sorted as "Descending"
However, the report shows the data in ascending order.

I notice the dates early in the month as 8/3/2016 showing before 8/25/2016
Is this caused because the date isn't showing as 8/03/2016?
If so, how do I fix it?
If not, how do I fix it?

I have attached pictures of the query and the resulting report.
Report-order-Example-160920.JPGQuery-Example-160920.JPG
Thanks!
Dennis
0
Comment
Question by:DGWhittaker
  • 6
  • 4
  • 3
  • +3
17 Comments
 
LVL 35

Expert Comment

by:Pawan Kumar
ID: 41806347
ADD ORDER by Date DESC..
0
 
LVL 35

Expert Comment

by:Pawan Kumar
ID: 41806351
Could you please share the query with us?

Or you many need to cast that column as CAST(dt AS DATE)
0
 

Author Comment

by:DGWhittaker
ID: 41806353
Thanks Pawan!
Where should I add this?
Thanks!
Dennis
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:DGWhittaker
ID: 41806356
Here is the SQL:

SELECT CallResults.[Record Date], CallResults.[Caller ID], CallResults.[Result ID], CallResults.Notes, CallResults.[VIN #], CallResults.Source
FROM CallResults
WHERE (((CallResults.[VIN #])=[Forms]![InProgressSurveys]![VIN]))
ORDER BY CallResults.[Record Date] DESC;
0
 
LVL 35

Expert Comment

by:Pawan Kumar
ID: 41806361
Pls try below-

SELECT CallResults.[Record Date], CallResults.[Caller ID], CallResults.[Result ID], CallResults.Notes, CallResults.[VIN #], CallResults.Source
FROM CallResults
WHERE (((CallResults.[VIN #])=[Forms]![InProgressSurveys]![VIN]))
ORDER BY CAST(CallResults.[Record Date] AS DATE) DESC;
0
 
LVL 10

Accepted Solution

by:
Anders Ebro (Microsoft MVP) earned 2000 total points
ID: 41806362
The sort order should always be set in the report. Or, more correctly any sort order(or group by) in the report will override the queries sort, therefore the report seems the most sensible place to put the sort.

In Access 2016 when the report is open in design view you should see a "Group & Sort" button in the ribbon. Click that, and below your report a small window will show up. Set the sort there.
2
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 41806380
This is so true. In fact, any sorting should be removed from the query, and all sorting should be specified in the report.

/gustav
0
 
LVL 35

Expert Comment

by:Pawan Kumar
ID: 41806387
This is basically depends..

If your query can use index and doesn't hamper the performance we can use.

Also if the data set is very small like 10-15 rows we can use order by unless it is not spilling to tempdb or user database.
0
 
LVL 10

Expert Comment

by:Anders Ebro (Microsoft MVP)
ID: 41806388
To expand on Gustavs comment, there are some scenarios that can include sorting. E.g. if you want the top 10 salesman in a division. In that case you need the sort in the query, because it affects the selection.
0
 

Author Comment

by:DGWhittaker
ID: 41806390
Thanks All!
I had a prior sort in front of the date on the report that tossed this into a tail spin.
This was found and corrected within the report level sort as suggested by
Anders.

Dennis
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 41806404
No Pawan, it doesn't depend.
If no sorting is specified in the report, you may in some cases seem get away with sorting in the query but you can't rely on that. The only safe method is to leave out sorting in the query and specify sorting in the report.

Of course, you have to set sorting in the query for a TOP n to work, but still sorting must be specified in the report.

/gustav
0
 
LVL 35

Expert Comment

by:Pawan Kumar
ID: 41806407
Ok Thanks Gustav Brock !1
0
 
LVL 10

Expert Comment

by:Anders Ebro (Microsoft MVP)
ID: 41806412
@ Pawan
With respect, please notice this question has no SQL server tags. As such, suggesting the use of Cast (Which is SQL server syntax) really makes no sense in this context. Not to mention that it in no way solves the posters issue.
0
 
LVL 35

Expert Comment

by:Pawan Kumar
ID: 41806415
Ohh my bad didnt check the DB type ! Thanks Anders !
0
 
LVL 58
ID: 41806423
<<With respect, please notice this question has no SQL server tags.>>

 Still could have been a SQL back end.   With Access, you never know unless you ask<g>

Jim.
0
 
LVL 26

Expert Comment

by:Nick67
ID: 41807123
Still could have been a SQL back end.
True enough, but unless you are building a pasthrough, CAST will fall over.

If no sorting is specified in the report, you may in some cases seem get away with sorting in the query but you can't rely on that.
+1
In fact, a query left unsorted MAY be ordered by primary key-- and sometimes behave that way for a very long time -- and then one day switch to a new sort order.
Reports can be even more capricious in that regard.
Regardless of what you do in the query, set a sort in the report.

Access is smarter than it was in the past.
The sort order in the query may be superfluous if identical to that in the report, but it doesn't affect performance if that is true.
Now, one sort order in the report and another in the query can be a bad combination.
And, ensuring that ANYTHING you sort on, whether its in the report or the query, has an index when that makes sense (not Boolean values, and not massive numbers of unique values) is a good idea.
0
 

Author Closing Comment

by:DGWhittaker
ID: 41819641
Thanks Anders!
Dennis
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question