That is the error you generally get when you create an aggregate query and
fail to include one of the fields from the SELECT statement in the GROUP BY
statement.
Dale
I'm not sure why you even need the zAcctNum table in the picture, unless
you
are using this to "filter" the AcctIDs visible in tblProvider.
Instead of the way you have it, why not try:
SELECT tblProvider.ProviderID,
tblProvider.AcctID,
Sum(Nz(tblPayDetail.[BillPayAmt]))
FROM tblProvider
LEFT JOIN tblPayDetail
ON tblProvider.AcctID = tblPayDetail.AcctID
GROUP BY tblProvider.ProviderID, tblProvider.AcctID
ORDER BY tblProvider.AcctID
That should be faster than using the DSUM function. Then, if you still
need
the zAcctNum table to "filter" the result set, add that table back into
the
query and join it to tblProvider with an inner join.
HTH
Dale
I get the following error message when executing the code below:
The specified field '[AcctID]' could refer to more than one table
listed in the FROM clause of your SQL statement.
SELECT tblProvider.ProviderID, tblProvider.AcctID, CCur(Nz(DSum
("[BillPayAmt]","[tblPayDetail]","[AcctID] = " & [AcctID]))) AS
AcctTotal
FROM zAcctNum INNER JOIN tblProvider ON zAcctNum.AcctID =
tblProvider.AcctID
ORDER BY tblProvider.AcctID;
How do I code this to fix this problem?
Thanks for your help, Dale!
I created a query to do the INNER JOIN as you suggested, and now IT
WORKS as I want.
However, your suggestion to use Sum(Nz(tblPayDetail.[BillPayAmt]))
instead of DCount, I could NOT get to work. Since I don't know what
I'm doing, that's understandable.
The Error I get when using Sum(Nz(tblPayDetail.[BillPayAmt])) is:
"You tried to execute an a query that does not include the specified
expression 'ProviderID' as part of an aggregate function.
Maybe you could modify my new code below to show me how to use Sum(Nz
(tblPayDetail.[BillPayAmt])) instead of Dcount.
HERE IS MY NEW CODE THAT WORKS
SELECT [tblProvider Query].ProviderID, [tblProvider Query].AcctID,
[tblProvider Query].AcctNum, [tblProvider Query].PayeeID, [tblProvider
Query].PayeeName, [tblProvider Query].CoNameID, [tblProvider
Query].CoName, CCur(Nz(DSum("[BillPayAmt]","[tblPayDetail]","[AcctID]
= " & [AcctID]))) AS AcctTotal, CCur(Nz(DSum
("[BillPayAmt]","[tblPayDetail]","[PayeeID] = " & [PayeeID]))) AS
PayeeTotal, CCur(Nz(DSum("[BillPayAmt]","[tblPayDetail]","[CoNameID] =
" & [CoNameID]))) AS CoNameTotal
FROM [tblProvider Query]
ORDER BY [tblProvider Query].AcctNum, [tblProvider Query].PayeeName,
[tblProvider Query].CoName;
Thanks,
Bernie