Solved

Access 2016 - Sort order on report from query

Posted on 2016-09-20
17
48 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 28

Expert Comment

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

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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 28

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 7

Accepted Solution

by:
Anders Ebro (Microsoft MVP) earned 500 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 49

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 28

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 7

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 49

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 28

Expert Comment

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

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 28

Expert Comment

by:Pawan Kumar
ID: 41806415
Ohh my bad didnt check the DB type ! Thanks Anders !
0
 
LVL 57
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

840 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