Dale,
Here's the SQL statement... (Select query)
SELECT tblFabricInventory.StyleID, IIf([RcvdDate] Between
[Forms]![frmInspectionReportsDialog]![BeginningDate] And
[Forms]![frmInspectionReportsDialog]![EndingDate],1,0) AS InRange,
*IIf([DefectID]=1 And
[Forms]![frmInspectionReportsDialog]![AverageOrCount1]=1,Avg([DefectCount]),
Sum([DefectCount]))
AS 1*
FROM tblInspectionDefects LEFT JOIN tblFabricInventory ON
tblInspectionDefects.RollNo = tblFabricInventory.RollNo
GROUP BY tblFabricInventory.StyleID, IIf([RcvdDate] Between
[Forms]![frmInspectionReportsDialog]![BeginningDate] And
[Forms]![frmInspectionReportsDialog]![EndingDate],1,0)
HAVING (((tblFabricInventory.StyleID) Like
[Forms]![frmInspectionReportsDialog]![cboStyleID1] & "*") AND
((IIf([RcvdDate] Between
[Forms]![frmInspectionReportsDialog]![BeginningDate] And
[Forms]![frmInspectionReportsDialog]![EndingDate],1,0))=1))
ORDER BY tblFabricInventory.StyleID;
* Problem Code *
Error = You tried to execute a query that doesn't include the specified
expression <name> as part of an aggregate function. (Error 3122)
I used some "alias" control names in my first post for ease/clarity... this
SQL uses the real control names.
Any help would be appreciated... but, I may have to create multiple SQLs,
and apply then to the report according to the dialog form values.
Thanks,
Al Camp
Dale Fye said:
I only had this one field in my query, but it worked exactly as you
indicated you wanted it to. If this doesn't work, post the entire SQL
string and I will take a look at it.
Dale
Dale,
Thanks for responding. I'll try your solution, but... hmm... I'm
pretty
sure that's what I tried right at the start.
I remember being surprised that I got an "aggregate" error, because
the
results of my IIF were aggregates. Maybe I had a finger check...
Anyhow... thanks for the help. I'll give that another shot.
Al Camp
Al,
Since I don't know what the rest of your query looks like, I cannot
help
you
with that. However, I was able to compute the AverageOrSum of a
numeric
column using the following:
AverageOrSum:
IIF([Forms]![yourForm]![og_averageORSum]=1,Avg([DefectCount]),Sum([DefectCou
nt]))
Total: Expression
HTH
Dale
On a Totals query for a report, I want the user to be able to check an
option box on a Dialog form and have an Average, or Sum returned by
the
query.
The form is frmDialog, and the Option Frame on that form is
[AverageOrSum]
and it has 2 checkbox elements...
[Average]=1 and [Sum]=2
At present, I have the Sum portion of this problem working with
this
as
a
calculated column...
SumOf1s : Sum(IIf([DefectID]=1,[DefectCount],0)))
Then I tried adding the Average portion... (all on one line)
SumOrAvg1s : Sum(IIf([DefectID]=1
AND Forms!frmDialog!AverageOrSum =
1,[DefectCount],Avg([DefectCount])))
I get a "Can't use aggregate function" (the AVG in this
calculation)
error.
Any help will be appreciated.
As always... Thanks,
Al Camp