Solved Query does not Export when Column Heading are Used

RogerCooper

Registered User.
Local time
Yesterday, 19:44
Joined
Jul 30, 2014
Messages
764
A customer wants me to e-mail a spreadsheet showing sales and columns for each month (even future months). Here is a simplified version of the query.

Code:
TRANSFORM Sum(dbo_History.Net_Sales) AS SumOfNet_Sales
SELECT dbo_History.CUSTOMER_NAME AS [Customer Name]
FROM dbo_History
WHERE (((dbo_History.BUYING_GROUP)="ITEG") AND ((dbo_History.YEAR)=Year(Date())))
GROUP BY dbo_History.CUSTOMER_NAME
ORDER BY dbo_History.CUSTOMER_NAME, dbo_History.Month
PIVOT dbo_History.Month In (1,2,3,4,5,6,7,8,9,10,11,12);

The recordset appears on the screen correctly. When I export it as a spreadsheet, only the header row appears, all other rows are blank.

If I don't specify the column headings it shows the numbers correctly, but it does not show columns for future months as the customer has requested.

Is this a bug in Access?

I probably could work around this issue by creating a table and then exporting the table, but I am looking for a better solution
 
How exactly are you exporting the query to Excel? Are you using code or the Wizard?
 
I have used code and exported it manually. The result is the same.
 
Try encapsulating the crosstab query in a select query:
Code:
SELECT X.* FROM
(TRANSFORM ...) AS X

Code:
ORDER BY ... dbo_History.Month
What is this good for?
 
I have used code and exported it manually. The result is the same.
I just gave it a try, and here's what I got.

1680887213002.png


1680887241128.png


1680888007201.png
 
Last edited:
Getting rid of the OrderBy Month fixed it. Thank you for the help.
 

Users who are viewing this thread

Back
Top Bottom