Solved

Access 2016 - Sort order on report from query

Posted on 2016-09-20
17
38 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 18

Expert Comment

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

Expert Comment

by:Pawan Kumar Khowal
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
 

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 18

Expert Comment

by:Pawan Kumar Khowal
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 6

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 18

Expert Comment

by:Pawan Kumar Khowal
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
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
LVL 6

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 18

Expert Comment

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

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 18

Expert Comment

by:Pawan Kumar Khowal
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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now