Displaying totals within a specified date range in Microsoft Access

跟風遠走 提交于 2019-12-13 18:17:49

问题


Although I have experience with SQL and generating HTML reports with PHP, I'm a relative beginner with Microsoft Access.

I'm currently using Microsoft Access 2007 to connect to MSSQL Server 2005.

I have a table of Reports that looks something like this:

ReportID
DateCreated
Author
...

I'd like to create a form that allows the user to specify a start date and an end date, which would then show the number of reports by each author within the specified date range.

I've already done this in a form by first retrieving a list of unique authors into a combo box, and then allowing the user to select the author, start date, and end date, and displaying the count in a text box. However, I was wondering if there was an easier or better way, or if there was a way to display all of the authors and their totals simultaneously.

Thanks in advance :)


回答1:


You can have multiple fields associated with a combobox, so first have them pick the dates, then initialize the combobox with both author and total field.




回答2:


Make 2 unbound text controls for StartDate and EndDate. Put those in the header of a continuous form. Use a button or an AfterUpdate event to change the recordsource of your form. Something like:

me.recordsource = "SELECT author, count(*) from myTable GROUP BY author WHERE DateCreated BETWEEN  #" & format(startDate, "mm/dd/yyyy") & "# AND #" & format(startDate, "mm/dd/yyyy") & "#"



回答3:


This should show you all your information.

SELECT Author, Min(DateCreated) As Earliest, Max(DateCreated) As Latest, count(ReportID) As Titles
FROM YourTable
GROUP By Author
ORDER BY Author


来源:https://stackoverflow.com/questions/1228530/displaying-totals-within-a-specified-date-range-in-microsoft-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!