MS Access query date sorting question

Posted on 2016-11-17
Medium Priority
Last Modified: 2016-11-17
I have a simple query and I can't figure out how to first sort the data by year then by month
Question by:cssc1
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
  • 3
  • 3
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41892070
try this

SELECT tblContact.ContactID, tblGoodCatch.GoodCatchNo, tblContact.LastName, tblContact.FirstName, tblContact.JobTitle, tblContact.Foreman, tblContact.Shift, tblGoodCatch.GoodCatchDescription, tblGoodCatch.GoodCatchMonthlyWinner, tblContact.Terminated, tblGoodCatch.GoodCatch_NearMiss, tblGoodCatch.Date_, tblGoodCatch.Month___, tblGoodCatch.Year__, tblGoodCatch.SubmittedGC, tblGoodCatch.SubmittedNM
FROM tblContact INNER JOIN tblGoodCatch ON tblContact.ContactID = tblGoodCatch.GoodCatchNo
ORDER BY tblGoodCatch.Year__, tblGoodCatch.Date_;
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41892072
if you want to sort by Year, Month, use this

ORDER BY tblGoodCatch.Year__, tblGoodCatch.Month___

Author Comment

ID: 41892124
Sorry, but where do I put this code that you have provided?
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

LVL 120

Accepted Solution

Rey Obrero (Capricorn1) earned 2000 total points
ID: 41892128
here see query_Year_Date, query_Year_Month

Author Comment

ID: 41892161
Work fine, thanks!
LVL 38

Expert Comment

ID: 41892162
Notice that Month__ was added a second time to the grid but the show box is unchecked.  If you rearrange the grid to have year to the left of month, you don't need to repeat the month field.qrySort.JPG
Rather than using some number of underscores as a suffix, why not use a meaningful prefix to avoid conflict with reserved words?

CatchDate, CatchMonth, CatchYear.

Also, why are year and month separate from date?  Given their data content they don't seem to have any relationship to CatchDate so perhaps some prefix other than "Catch" makes more sense.

Author Closing Comment

ID: 41892163
Works fine, thanks!

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
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…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Suggested Courses

762 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