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
Solved

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

Posted on 2016-07-19
12
97 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

839 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