Link to home
Create AccountLog in
Avatar of SteveL13
SteveL13Flag for United States of America

asked on

Getting #Error in a subform footer

I have a main form, single form view.  And then in that form, a sub-form whish is a datasheet view.  In the footer section of the subform I am trying to sub the value of a field named txtGross (Gross is the control source).

What I have for the field's control source in the footer is =Sum([txtGross])  

But I'm getting #Error.

????
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

A form in datasheetview has no header or footer, so ...?
Avatar of SteveL13

ASKER

In design view it does.  I know it can't be visible but it is there.  And I thought that even if it won't be visible I could put calculated fields in it. ????
Never thought of that. But for what purpose? As you probably intend to use the sum elsewhere.
Are you sure the subform in question is not in Continuous Forms view?  I haven't tested it, but I wouldn't even expect to see the #Error in Datasheet View.  

Anyhow, this is the root of your problem:  "field named txtGross (Gross is the control source)"

The FIELD is actually named "Gross" if that is the control source.  txtGross is the name of the Textbox Control, not the field.  All of the aggregate functions (Sum, Avg, Max, etc) require the FIELD as the parameter, and using the control name will cause an error.  

So try this:

=Sum([Gross]) 

Open in new window

mbizup:  I changed it to =Sum([Gross])  and still get #Error.

Gustav:  I have it in the footer of the sub-form and am then pulling it over to the main form footer with: =[Forms]![frmAssemblySheetHeader].[Form]![subfrmAssemblySheetDetail].[Form].[txtSumGross].  But I get #Error in the main form footer also because of the #Error in the sub-form footer.
Does Sum([gross]) Produce an error on it’s own in the sub form, or just in the control on your main form?

Also, is Gross a calculated field?
Avatar of crystal (strive4peace)
crystal (strive4peace)

hi Steve,

> "... sub-form whish is a datasheet view.  In the footer section of the subform ..."

You will need to make a continuous (multiple items) form to be able to use the Header and Footer sections (or a single form but that only shows one record at a time) since Datasheet forms ignore calculated controls that are there.

have an awesome day,
crystal
ASKER CERTIFIED SOLUTION
Avatar of SteveL13
SteveL13
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Steve, since you put the calculation in the RecordSource, does it work now?  If now, would you share your formula?
Gross: IIf((Nz([MST],0)-Nz([Forms]![frmAssemblySheetHeader].[txtMoistureMax],0))*Nz([CleanCWT],0)*Nz([Forms]![frmAssemblySheetHeader].[txtDisSchd1],0)>=0,(Nz([MST],0)-Nz([Forms]![frmAssemblySheetHeader].[txtMoistureMax],0))*Nz([CleanCWT],0)*Nz([Forms]![frmAssemblySheetHeader].[txtDisSchd1],0),0)

(Is an Expression in query designer).
hi Steve,

assuming these are bound controls, instead of referring to controls in the expression, it would be better to make a query with the data for the calculation.  Then add that query to the RecordSource for the  subform -- using Left or Right join, whichever shows all records from the table for the subform. When the mainform record is updated (form AfterUpdate event), the subform will need to be requeried.

have an awesome day,
crystal
Thank you for the tip.  I appreciate it.
you're welcome, Steve.  In that query you will also need to put the key field(s) to link on.  Also, that is where I would put NZ so it doesn't have to be tested again.

have an awesome day,
crystal
Aggregate functions will not work over expressions like this.  You can Use SUM over fields:

SUM(fieldname)

Or expressions containing fields:

Sum(field1 + field2)

But using SUM on expressions containing control names will cause an error.

Perhaps you can break this down into an expression using only field names (not calculated fields or controls), and as Crystal suggested, revise your query to include these.
My solution worked.