Solved

Access 2016 - Sort order on report from query

Posted on 2016-09-20
17
78 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
  • +3
17 Comments
 
LVL 29

Expert Comment

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

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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

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 29

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 8

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 51

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 29

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 8

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 51

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 29

Expert Comment

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

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 29

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

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

623 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