Link to home
Start Free TrialLog in
Avatar of Derek Brown
Derek BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Calculated control problem

A & B  are controls on a subform that get their data from other fields. A is from a total field on the subform's subform.

When I open the form for the first time All works well (Capture5.PNG)
When I duplicate all of the records in a project and move to the duplicate AB&C are correct but I get error in D. The really strange thing is that I now get the same error at D in ALL records including the original that was duplicated. When I close the form and reopen all records are correct including the duplicate.

I have tried refresh dirty update etc but the only way to get back to correct calculated fields (D) is to close the form and re-open. How can that be? It's as if duplicating the records has switched off certain calculates controls.

A =VPSubForm.Form!TVPCost
B =TotalDoorCost
C =A+B
D =VPSubForm.Form!TVPCost+TotalDoorCost

A. B, and C are all correct.  D Gives error
Capture5.PNG
Capture6.PNG
Avatar of PatHartman
PatHartman
Flag of United States of America image

When you are doing arithmetic with fields that may be null, you need to take that into consideration.  See if using the Nz() function solves the problem.

D =Nz(VPSubForm.Form!TVPCost,0) + Nz(TotalDoorCost,0)
Avatar of Derek Brown

ASKER

Thanks Pat

I don't use Nz because if I return a zero when a control is not responding then my total will be out.

The weird thing is that I can see the controls on all subform and they all have values.

To solve the problem, I have discovered, I need a controls on the subform that get their data from the Subform's subform's calculated control. As in the example I can then add these together. If I don't do this and i refer to the subform's subform controls directly the problem then effects all the viewed record across all the entire Dbase. The data is not changing just the calculated fields. I do not understand this. You would think that if I can open the database and all is well that merely adding data to the same tables could not possibly effect all the calculated controls for other data on the dbase. But it does. I am not sure if there is an answer to this one.
Access maintains only one set of properties for each control.  That's why when you have an unbound control on a continuous form, it always contains the same value across all instances.  You may find things work better if you do the initial calculation in the Form's RecordSource query.  Then you can aggregate a bound field.

Select ..., A + B as AB From yourtable;

So you can bind a control to AB and sum that rather than using =A+B as the ControlSource.
Thank you

The subform's subform table is a different table to the subforms table and the values that are calculated are from the subforms subform. When i tried to join them in the main subform's underlying query so that I could do the calculations in the query I find that the subforms table is then not updateable.

So the reason for the calculated control is to sum the data from a different table or sub subform and then add it to the sum of the values on the main subform. Adding values from two tables.
ASKER CERTIFIED SOLUTION
Avatar of PatHartman
PatHartman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Pat

I was pretty sure I did not have any aggregates in the query. When I tried it.

But what I was trying to do was to add to the main form query the query from the subform so that I could use the new query for cross table calculations and when attempting to change values in fields on either the subform or the form (Can't remember which) I got a "this recordset is not updateable"
Me.sfrmXXX.Form!SumABCD

Brilliant as usual

Thanks Derek