How to use data of Subform with data of the main form?

  • Thread starter Thread starter orsonros
  • Start date Start date
O

orsonros

Hi!
I have data on a subform text box that I have to use for calculation
with another text box data on the main form. Please advise how to go
about it.

ORS
 
Hi!
I have data on a subform text box that I have to use for calculation
with another text box data on the main form. Please advise how to go
about it.

ORS

Could you explain the nature of the calculation? Do you want to have
the calculation result on each record of the subform, as a summary of
the records on the subform, on the mainform, or what?

John W. Vinson[MVP]
 
Hi! John

Actually I have a runningsum of profit or Loss per day in a text box on
the subform. I need that value to be added to the Capital on the main
form.
How do you use data from the subform to the main form and vice versa.

thanks

Ors
 
One question?

Do you want the calculated value in the subform to be added to a record in
an underlying table in the main form or just used in another calculation on
the main form?

If its the latter then you could refer to the control with the calculated
value from the subform (using its name) as the relevant control source in the
main form.

If it is the former then I dont know either and would also to find out as I
would like to do something very similar with one of my forms.

John
 
Hi! John

Actually I have a runningsum of profit or Loss per day in a text box on
the subform. I need that value to be added to the Capital on the main
form.
How do you use data from the subform to the main form and vice versa.

Storing derived data such as this in your table accomplishes
three things: it wastes disk space; it wastes time (almost
any calculation will be MUCH faster than a disk fetch); and
most importantly, it risks data corruption. If one of the
underlying fields is subsequently edited, you will have data
in your table WHICH IS WRONG, and no automatic way to detect
that fact.

Just redo the calculation whenever you need it, either as a
calculated field in a Query or just as you're now doing it -
in the control source of a Form or a Report textbox.

You can use a Query (including a totals query) to calculate the
Capital value dynamically. That way you'll be sure it's right.

If you really want to refer to a mainform control on a subform, you
can use an expression

Parent!Controlname

To refer to a control on the *CURRENTLY SELECTED* record on a Subform
from an expression on the parent form, you can use

=subformcontrol.Form!controlname

where subformcontrol is the Name property of the "box" containing the
subform (this might be the same or different from the name of the form
within that control). Note that this will not pick up a running sum,
since you have no way of knowing which record on the subform has the
focus.

John W. Vinson[MVP]
 
Hi! John's,

I've managed to solve it.
Thanks for showing me this
= subformcontrol.Form!controlname using this I could get the value into
a box for calculation.

Thanks
Ors
 
Back
Top