SteveL13
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.
????
What I have for the field's control source in the footer is =Sum([txtGross])
But I'm getting #Error.
????
A form in datasheetview has no header or footer, so ...?
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:
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])
ASKER
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]![frmAssemblySheet Header].[F orm]![subf rmAssembly SheetDetai l].[Form]. [txtSumGro ss]. But I get #Error in the main form footer also because of the #Error in the sub-form footer.
Gustav: I have it in the footer of the sub-form and am then pulling it over to the main form footer with: =[Forms]![frmAssemblySheet
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?
Also, is Gross a calculated field?
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
> "... 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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Steve, since you put the calculation in the RecordSource, does it work now? If now, would you share your formula?
ASKER
Gross: IIf((Nz([MST],0)-Nz([Forms ]![frmAsse mblySheetH eader].[tx tMoistureM ax],0))*Nz ([CleanCWT ],0)*Nz([F orms]![frm AssemblySh eetHeader] .[txtDisSc hd1],0)>=0 ,(Nz([MST] ,0)-Nz([Fo rms]![frmA ssemblyShe etHeader]. [txtMoistu reMax],0)) *Nz([Clean CWT],0)*Nz ([Forms]![ frmAssembl ySheetHead er].[txtDi sSchd1],0) ,0)
(Is an Expression in query designer).
(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
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
ASKER
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
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.
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.
ASKER
My solution worked.