There are no aggregate functions in your query, so I don't understand
why you're using GROUP BY and HAVING. As far as I know this is a simpler
equivalent:
SELECT
[Plant 01 Raw Warehouse Flow Parts].Date,
[Plant 01 Raw Warehouse Flow Parts].Part,
[Flow Parts Cost].[Last Cost],
[Plant 01 Raw Warehouse Flow Parts].Serv,
[Plant 01 Raw Warehouse Flow Parts].Raw,
[Plant 01 Raw Warehouse Flow Parts].[Offsite Serv],
[Plant 01 Raw Warehouse Flow Parts].[Offsite Raw],
[Serv]+[Raw]+[Offsite Serv]+[Offsite Raw] AS [Inv Pcs],
[Flow Parts Cost].[Last Cost]*[Inv Pcs] AS [Inv $]
FROM [Plant 01 Raw Warehouse Flow Parts] LEFT JOIN [Flow Parts Cost]
ON [Plant 01 Raw Warehouse Flow Parts].Part = [Flow Parts Cost].Part
WHERE [Plant 01 Raw Warehouse Flow Parts].Date=#1/23/2007# ;
Anyway, I think the way to do what you want is to a form to supply the
date and worksheet name. You'll need a form (maybe you're using one
already to display the data); I'll call it "frmX".
Put two textboxes on frmX; call one of them txtExportDate and the other
txtSheetName. Also a commandbutton; let's call this cmdExport.
Turn the query into a parameter query that gets the date the user enters
on the form:
PARAMETERS [Forms]![frmX]![txtExportDate] DateTime;
SELECT
[Plant 01 Raw Warehouse Flow Parts].Date,
[Plant 01 Raw Warehouse Flow Parts].Part,
[Flow Parts Cost].[Last Cost],
[Plant 01 Raw Warehouse Flow Parts].Serv,
[Plant 01 Raw Warehouse Flow Parts].Raw,
[Plant 01 Raw Warehouse Flow Parts].[Offsite Serv],
[Plant 01 Raw Warehouse Flow Parts].[Offsite Raw],
[Serv]+[Raw]+[Offsite Serv]+[Offsite Raw] AS [Inv Pcs],
[Flow Parts Cost].[Last Cost]*[Inv Pcs] AS [Inv $]
FROM [Plant 01 Raw Warehouse Flow Parts] LEFT JOIN [Flow Parts Cost]
ON [Plant 01 Raw Warehouse Flow Parts].Part = [Flow Parts Cost].Part
WHERE [Plant 01 Raw Warehouse Flow Parts].Date=
[Forms]![frmX]![txtExportDate];
Then use something like this in the Click event procedure of cmdExport,
replacing qryXXX with the actual name of the query and using the actual
location of the destination file:
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
"qryXXX", "D:\Folder\Filename.xls", True, _
Me.txtSheetName.Value & "$"
(I can never remember whether the last character needs to be a $ or a !)
Then it's just a matter of entering the date and worksheet name on the
form and clicking the button.
The next stage of automation is to generate the worksheet names
automatically.
SELECT [Plant 01 Raw Warehouse Flow Parts].Date, [Plant 01 Raw
Warehouse Flow Parts].Part, [Flow Parts Cost].[Last Cost], [Plant 01
Raw Warehouse Flow Parts].Serv, [Plant 01 Raw Warehouse Flow
Parts].Raw, [Plant 01 Raw Warehouse Flow Parts].[Offsite Serv], [Plant
01 Raw Warehouse Flow Parts].[Offsite Raw], [Serv]+[Raw]+[Offsite Serv]
+[Offsite Raw] AS [Inv Pcs], [Flow Parts Cost].[Last Cost]*[Inv Pcs]
AS [Inv $]
FROM [Plant 01 Raw Warehouse Flow Parts] LEFT JOIN [Flow Parts Cost]
ON [Plant 01 Raw Warehouse Flow Parts].Part = [Flow Parts Cost].Part
GROUP BY [Plant 01 Raw Warehouse Flow Parts].Date, [Plant 01 Raw
Warehouse Flow Parts].Part, [Flow Parts Cost].[Last Cost], [Plant 01
Raw Warehouse Flow Parts].Serv, [Plant 01 Raw Warehouse Flow
Parts].Raw, [Plant 01 Raw Warehouse Flow Parts].[Offsite Serv], [Plant
01 Raw Warehouse Flow Parts].[Offsite Raw]
HAVING ((([Plant 01 Raw Warehouse Flow Parts].Date)=#1/23/2007#));
The only difference between the worksheets is the #1/23/2007# which I
will go in and manually change to #1/30/2007#, and then #2/6/2007# and
so on...........When I change the date in the query I get new results
because my table has for example 50 records for 1/30/2007, 50 records
for 2/6/2007 and so on, yet the query has the same name when I save
it.
--
John Nurick [Microsoft Access MVP]
Please respond in the newsgroup and not by email.- Hide quoted text -
- Show quoted text -