I have a query for every month of the year and a report that has all 12
months on that report. What I would like to be able to do is to have one
query and show each month on the report, but i would also like to able to
input the time span that the query should calculate. I hope this make sense.
Please let me know if this needs for explination. Thanks for your time.
|
|
0
|
|
|
|
Reply
|
Utf
|
2/11/2008 6:16:00 PM |
|
On Mon, 11 Feb 2008 10:16:00 -0800, Erik <Erik@discussions.microsoft.com>
wrote:
>I have a query for every month of the year and a report that has all 12
>months on that report. What I would like to be able to do is to have one
>query and show each month on the report, but i would also like to able to
>input the time span that the query should calculate. I hope this make sense.
>Please let me know if this needs for explination. Thanks for your time.
Please open one of your queries, select View... SQL, and post the SQL text
here.
It's certainly possible to do this using a parameter query, and you do indeed
need only one query, not 12. Rather than twelve subreports (if that's what you
now have) you can use a single Report, and use its Sorting and Grouping to
group by the month.
--
John W. Vinson [MVP]
|
|
0
|
|
|
|
Reply
|
John
|
2/11/2008 6:29:56 PM
|
|
I am not to sure on how to setup the Sorting and Grouping feature. Is there
any examples or information you might be able to give. Thanks
"John W. Vinson" wrote:
> On Mon, 11 Feb 2008 10:16:00 -0800, Erik <Erik@discussions.microsoft.com>
> wrote:
>
> >I have a query for every month of the year and a report that has all 12
> >months on that report. What I would like to be able to do is to have one
> >query and show each month on the report, but i would also like to able to
> >input the time span that the query should calculate. I hope this make sense.
> >Please let me know if this needs for explination. Thanks for your time.
>
> Please open one of your queries, select View... SQL, and post the SQL text
> here.
>
> It's certainly possible to do this using a parameter query, and you do indeed
> need only one query, not 12. Rather than twelve subreports (if that's what you
> now have) you can use a single Report, and use its Sorting and Grouping to
> group by the month.
> --
> John W. Vinson [MVP]
>
|
|
0
|
|
|
|
Reply
|
Utf
|
2/11/2008 6:51:02 PM
|
|
It depends to some degree whether you are returning rows from the table(s) or
aggregating values. If you are simply returning rows then you can include
two computed columns in a query to return the Year and month (as numbers) for
each date value, e.g.
SELECT TransactionID, TransactionDate, Amount,
YEAR(TransactionDate) AS TransactionYear,
MONTH(TransactionDate) AS TransactionMonth
FROM Transactions;
You can then group a report, using its internal sorting and grouping
maechanism, firstly on the TransactionYear and then on the TransactionMonth,
giving the TransactionMonth group a Group Header. Include the
TransactionYear and TransactionMonth in the group header and the other fields
in the detail section. You could of course give both groups group headers if
you prefer and out the year in one and the month in the other so that the
year only prints once in the report.
If you are aggregating data you do much the same but group the query on the
year and month, e.g.
SELECT YEAR(TransactionDate) AS TransactionYear,
MONTH(TransactionDate) AS TransactionMonth,
SUM(Amount) AS TotalMonthlyAmount
FROM Transactions
GROUP BY YEAR(TransactionDate), MONTH(TransactionDate);
With a query like this you' d probably not use group headers in the report
at all, or just have a TransactionYear group header, putting the month and
the total amount in the detail section.
To restrict the report to date range you can include parameters in the
query. Date/time parameters are best declared as otherwise a date in short
date format might be interpreted as an arithmetical expression rather than a
date and give the wrong results, so taking the first query above as an
example, adding parameters would give you;
PARAMETERS [Enter start date:] DATETIME,
[Enter end date:] DATETIME;
SELECT TransactionID, TransactionDate, Amount,
YEAR(TransactionDate) AS TransactionYear,
MONTH(TransactionDate) AS TransactionMonth
FROM Transactions
WHERE TransactionDate >= [Enter start date:]
AND TransactionDate < [Enter end date:] + 1;
The method used her for defining the data range, returning all rows on or
after the start date and before the day following the end date, makes sure
that if any TransactionDate values in the table inadvertently include
non-zero times of day (which can easily happen if you haven't taken steps in
the table design to prevent this, i.e. a validation rule limiting the values
to dates with non-zero times of day) and those dates fall on the final day of
the range, are nevertheless returned. A BETWEEN….AND operation would exclude
such dates.
I've shown the queries as SQL here, but you can also build them visually in
query design view of course.
You can also aggregate values in the report; for instance with a report
based on the first query you could have group footers for the month and year,
and a report footer and out a text box in each with a ControlSource of
=Sum([Amount]). This would give you sub-totals by month and year and an
overall grand total. You can also use other aggregation operators of course
as well as Sum, e.g. Avg, Min or Max.
I hope that gets you started. If you need any help applying it to your own
database post back.
Ken Sheridan
Stafford,
"Erik" wrote:
> I have a query for every month of the year and a report that has all 12
> months on that report. What I would like to be able to do is to have one
> query and show each month on the report, but i would also like to able to
> input the time span that the query should calculate. I hope this make sense.
> Please let me know if this needs for explination. Thanks for your time.
|
|
0
|
|
|
|
Reply
|
Utf
|
2/11/2008 7:07:01 PM
|
|
|
3 Replies
148 Views
(page loaded in 0.136 seconds)
Similiar Articles: Which query is being used by which form/report? - microsoft.public ...Is there any way to find out whether a query is being used, and by which reports or forms? Thanks, Dean S ... get value from a query /set a variable for a report - microsoft ...I put this question in the forms area -- it is a form/report problem. - don't mean to double post, but I should have put it in this area instead. so... Pop up Form to set parameter of query to generate a report ...I have a pop up form that opens when I run a report via a macro. The query searchs for an item (drug) that has 2 different mnemonics. (fields are mne... Open Report Based on Query - microsoft.public.access.reports ...Change the way you open the report so you can open it from different forms Use the WhereCriteria of the open report command line, living the RecordSource without a ... Import multiple forms, queries from another database - microsoft ...My work: I manage and create/update queries, forms, vba code, macros, modules and reports in this database. My partner: Manages and updates the sole table in the ... Viewing Query Total in Form - microsoft.public.access.forms ...I have a form where I input purchases for customers. I also have a query that I use to make a report as a reciept to show the totals for items input.... Concatenate Field for Report/Query - microsoft.public.access.forms ...I have a table with just Authors that has a relationship to the Title table. In most instances there is more than one author per title. When running a query/report ... How to minimize a form - Access 2007 - microsoft.public.access ...The pop up form accepts parameters which are passed to a query which is the source for a report. When the report's preview runs it appears behind the request form. Filter report from pop up form - microsoft.public.access.queries ...Hi to everyone, I'm trying to use the code below in my report. I took it for the well- know sample report collection. Private Sub Command28_Click() ... Parameter query in Access 2003 report - microsoft.public.access ...Access 2003/2002 Sample: Using Parameters with Queries and Reports Sample Database Microsoft Access database provides example forms, queries, and reports that ... MS Access Objects: Tables, Forms, Queries, and ReportsMS Access database objects are its tables, forms, queries and reports. To design a useful database we need to know how the database records and fields ... Amazon.com: Microsoft Access 2003 Forms, Reports, and Queries ...Paul McFedries is the president of Logophilia Limited, a technical writing company. Now primarily a writer, Paul has worked as a programmer, consultant, spreadsheet ... Microsoft Office Access 2007 Forms, Reports, and Queries [Paperback]Paul McFedries is the president of Logophilia Limited, a technical writing company. Now primarily a writer, Paul is well known as a teacher of Microsoft Office and ... Use a query as the record source for a form or report - Access ...Show All Hide All You can use a query to supply data to a form or report. You can use a query when you create the form or report, or you can change an existing form ... Using parameters with queries and reports - Access - Office.comRecall that when you click OK, the form is hidden so that the parameters can remain available to the report's underlying query. If the form is closed, the report will be ... 7/17/2012 8:13:36 AM
|