Solved

Populate access combo box with month name and year from data table.

Posted on 2016-07-19
12
84 Views
Last Modified: 2016-07-19
I have 32000 records in my table and I need my monthly report to show me all records for the month of June 2016 for example, or January 2015, just by selecting "January 2015" from combo box. This combo box needs to be sequentially populated when opening a report and if a new month is detected to add it to combo box.

Any help is appreciated.
0
Comment
Question by:toalexsandr
  • 6
  • 4
  • 2
12 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41719416
i'll assume you have a date field in your table, so use this as the rowsource of your combo box

select format([dateField], "mmmm yyyy")  from tableName
group by  format([dateField], "mmmm yyyy")
 order by  [dateField]

use a query as recordsource of your form/report using the value of the selected item form the combo box

select * from tableName
where  format([dateField], "mmmm yyyy") = Forms!NameofForm.NameofCombo
0
 
LVL 26

Expert Comment

by:Shaun Kline
ID: 41719469
From a usability stand point, consider what will happen if your application is used for 3, 5, 10 years. Think about the number of entries that will appear in the combo box. You may want to consider using two combo boxes, one for Month that you fill will all months, and one for year that you pull from your data.
0
 

Author Comment

by:toalexsandr
ID: 41719573
Rey here is what I had to use because of errors but its not sorting it properly...

SELECT Format([tb_WOInspectionNAS].[QC Inspection Date],"mmmm yyyy") AS InspDate
FROM tb_WOInspectionNAS
GROUP BY Format([tb_WOInspectionNAS].[QC Inspection Date],"mmmm yyyy")
ORDER BY Format([tb_WOInspectionNAS].[QC Inspection Date],"mmmm yyyy");

April 2016
August 2015
December 2015
February 2016
January 2016
July 2015
July 2016
June 2015
June 2016
March 2016
May 2016
November 2015
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

Author Comment

by:toalexsandr
ID: 41719575
Shaun, its a good point. I think i may need to do that down the road.
0
 
LVL 26

Expert Comment

by:Shaun Kline
ID: 41719580
If you want to sort your dates in calendar order, change for your format in the order by to something like "yyyy-mm-dd". The group by may not like that though.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41719588
change the field in the order by

SELECT Format([tb_WOInspectionNAS].[QC Inspection Date],"mmmm yyyy") AS InspDate
FROM tb_WOInspectionNAS
GROUP BY Format([tb_WOInspectionNAS].[QC Inspection Date],"mmmm yyyy")
ORDER BY [tb_WOInspectionNAS].[QC Inspection Date]
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41719591
change the field in the order by

SELECT Format([tb_WOInspectionNAS].[QC Inspection Date],"mmmm yyyy") AS InspDate
FROM tb_WOInspectionNAS
GROUP BY Format([tb_WOInspectionNAS].[QC Inspection Date],"mmmm yyyy")
ORDER BY Format([tb_WOInspectionNAS].[QC Inspection Date] , "yyyy mm")
0
 

Author Comment

by:toalexsandr
ID: 41719592
i get this error "You tried to execute a query that does not include the specified expression '[tb_WOInspectionNAS].[QC Inspection Date]' as part of an aggregate function."
0
 

Author Comment

by:toalexsandr
ID: 41719593
nothing. same error.
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 41719596
SELECT Format([tb_WOInspectionNAS].[QC Inspection Date],"mmmm yyyy") AS InspDate
FROM tb_WOInspectionNAS
GROUP BY Format([tb_WOInspectionNAS].[QC Inspection Date],"mmmm yyyy"), Format([tb_WOInspectionNAS].[QC Inspection Date] , "yyyy mm")
ORDER BY Format([tb_WOInspectionNAS].[QC Inspection Date] , "yyyy mm")
0
 

Author Comment

by:toalexsandr
ID: 41719605
Worked perfect...Thanks a lot.

June 2015
July 2015
August 2015
November 2015
December 2015
January 2016
February 2016
March 2016
April 2016
May 2016
June 2016
July 2016
0
 

Author Closing Comment

by:toalexsandr
ID: 41719606
Works perfect. Thanks.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Modern/Metro styled message box and input box that directly can replace MsgBox() and InputBox()in Microsoft Access 2013 and later. Also included is a preconfigured error box to be used in error handling.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
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…

786 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