Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Report does not display same as query 1

Status
Not open for further replies.

kleinicus

MIS
Dec 4, 2002
98
US
I have a query that calculates totals and groups them by month, in chronological order. Here is the code...

Code:
SELECT Format$([Date],'mmmm yyyy') AS [Date By Month], Count(*) AS [Total Policies], Sum(TransactionsTable.Amount) AS [Total $]
FROM TransactionsTable
WHERE (((TransactionsTable.Agent)='S'))
GROUP BY Format$([Date],'mmmm yyyy'), Format$([Date],'yyyymm')
ORDER BY Format$([Date],'yyyymm');

This query was constructed this way because Access previously displayed the months in alphabetical order, rather than chronological.
My problem is that when I try to create a report based on that query, the months are displayed alphabetically instead of chronologically.
Can anyone help me get the months to display correctly?
Thanks.

SK
 
Im not 100% sure this would work, but if you were to use an unbound textbox on your report (having something along the lines of DatePart(m,[Date]) as its source), you should be able to sort the report on it.
You may have to set the source in the OnFormat event of the section for it to work, rather than setting the source in the actual textbox.

Let them hate - so long as they fear... Lucius Accius
 
Another option (figures I thought of it after hitting submit!)
add DatePart(m,[Date]) As DateSort to your query and sort the report by it - using the Sorting and Grouping button on the toolbar.

Let them hate - so long as they fear... Lucius Accius
 
I tried adding the SQL code you mentioned so that now my code looks like this...

Code:
SELECT Format$([Date],'mmmm yyyy') AS [Date By Month], Count(*) AS [Total Policies], Sum(TransactionsTable.Amount) AS [Total $], DatePart(m,[Date]) AS DateSort
FROM TransactionsTable
WHERE (((TransactionsTable.Agent)='Sara'))
GROUP BY Format$([Date],'mmmm yyyy'), Format$([Date],'yyyymm')
ORDER BY Format$([Date],'yyyymm');

When I try to run the report like this, Access says that DatePart(m,[Date]) is not part of an aggregate function.

Any suggestions?
 
Reports in Access typically ignore the sorting found in the query itself. You need to set your sorting critera (Format$([Date],'yyyymm')) in the Order By property of the Report.


-V
 
Change your query to:
Code:
SELECT Format([Date],'yyyymm') AS [SortYM], Format([Date],'mmmm yyyy') AS [Date By Month], Count(*) AS [Total Policies], Sum(TransactionsTable.Amount) AS [Total $]
FROM TransactionsTable
WHERE (((TransactionsTable.Agent)='S'))
GROUP BY  Format([Date],'yyyymm'), Format([Date],'mmmm yyyy');
Then use the Sorting and Grouping dialog in the report design to set the sorting to [SortYM].

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Where exactly do I find the Order By property of the report?
 
Duane, thanks for the query change. I changed the code and it displays properly in both the query results and in the report. Thanks a million!
 
Duane, the change that you suggested worked just fine except for one very tiny thing. At the end of the report, an error message pops up and says "No Current Record" and the last page of the report shows two fields called #Error.

Any suggestions on that?

SK
 
What section contains the problem controls and what are the Control Sources?

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top