?
Solved

Access 2016 - Sort order on report from query

Posted on 2016-09-20
17
Medium Priority
?
145 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 38

Expert Comment

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

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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 

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 38

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 11

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 53

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 38

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 11

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 53

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 38

Expert Comment

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

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 38

Expert Comment

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

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Audit trails are very important in any system to hold people responsible for certain transactions and hold them to take ownership of their actions. This article is dedicated to all novice "Microsoft Access" developers.
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

588 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