G
Guest
The following query which uses two linked summary queries, one of which has a
sub query, runs properly as a query, but will not run when assigned to a
string variable and run using docmd.runsql. The reason for wanting to use
the latter option is to make it easier to replace the literal critera with
variables assigned in an input form.
SELECT Act.Market, Act.Dept, Act.Account, Act.InvcAmt, Ref.RefAmt
FROM [SELECT stations.Market, APhist_PS.Dept, APhist_PS.Account,
CoreChart.Description, Sum(APhist_PS.[Invoice Amount]) AS InvcAmt
FROM ((APhist_PS INNER JOIN stations ON APhist_PS.[GL Unit] =
stations.StaNo) INNER JOIN datetab ON APhist_PS.[Invoice Date] =
datetab.date) INNER JOIN CoreChart ON APhist_PS.Account = CoreChart.Core
WHERE (((APhist_PS.[Invoice Date])>=#07/01/2006# And (APhist_PS.[Invoice
Date])<=#07/31/2006#))
GROUP BY stations.Market, APhist_PS.Dept, APhist_PS.Account,
CoreChart.Description
HAVING (((stations.Market)=382) AND ((APhist_PS.Dept)>"000"))]. AS Act LEFT
JOIN [SELECT FlashImpt.Month, FlashImpt.Dept, FlashImpt.Acctno,
Sum(FlashImpt.Amt) AS RefAmt
FROM FlashImpt
GROUP BY FlashImpt.Month, FlashImpt.Dept, FlashImpt.Acctno
HAVING (((FlashImpt.Month)=(SELECT datetab.Mnth
FROM datetab
WHERE (((datetab.date)>=#7/1/2006# And (datetab.date)<=#7/31/2006#))
GROUP BY datetab.Mnth)) AND ((FlashImpt.Acctno)>"499999"))]. AS Ref ON
(Act.Dept = Ref.Dept) AND (Act.Account = Ref.Acctno);
The above is the saved SQL view. I tried replacing the brackets around the
summary queries in the string assignment, but no dice. The query will run
either way: using parentheses for separators or the brackets inserted by
Access when the the query is saved.
DM
sub query, runs properly as a query, but will not run when assigned to a
string variable and run using docmd.runsql. The reason for wanting to use
the latter option is to make it easier to replace the literal critera with
variables assigned in an input form.
SELECT Act.Market, Act.Dept, Act.Account, Act.InvcAmt, Ref.RefAmt
FROM [SELECT stations.Market, APhist_PS.Dept, APhist_PS.Account,
CoreChart.Description, Sum(APhist_PS.[Invoice Amount]) AS InvcAmt
FROM ((APhist_PS INNER JOIN stations ON APhist_PS.[GL Unit] =
stations.StaNo) INNER JOIN datetab ON APhist_PS.[Invoice Date] =
datetab.date) INNER JOIN CoreChart ON APhist_PS.Account = CoreChart.Core
WHERE (((APhist_PS.[Invoice Date])>=#07/01/2006# And (APhist_PS.[Invoice
Date])<=#07/31/2006#))
GROUP BY stations.Market, APhist_PS.Dept, APhist_PS.Account,
CoreChart.Description
HAVING (((stations.Market)=382) AND ((APhist_PS.Dept)>"000"))]. AS Act LEFT
JOIN [SELECT FlashImpt.Month, FlashImpt.Dept, FlashImpt.Acctno,
Sum(FlashImpt.Amt) AS RefAmt
FROM FlashImpt
GROUP BY FlashImpt.Month, FlashImpt.Dept, FlashImpt.Acctno
HAVING (((FlashImpt.Month)=(SELECT datetab.Mnth
FROM datetab
WHERE (((datetab.date)>=#7/1/2006# And (datetab.date)<=#7/31/2006#))
GROUP BY datetab.Mnth)) AND ((FlashImpt.Acctno)>"499999"))]. AS Ref ON
(Act.Dept = Ref.Dept) AND (Act.Account = Ref.Acctno);
The above is the saved SQL view. I tried replacing the brackets around the
summary queries in the string assignment, but no dice. The query will run
either way: using parentheses for separators or the brackets inserted by
Access when the the query is saved.
DM