Update controls on main form from on changed values of the sub

L

Ladi

Dear friends and Pros

I'm trying to update a control in the main form with the Sum of the values
in the subform containing columns with numbers.
There is already the relationship between main table and child table, also
between the main form and sub.
The following function would update only one control on the first record.
I have Tables:
MainTab
ChildTabName
Forms:
FormName
SubformName
-------------------------------------------------
Form_ControlName= DSum("[ChildTabName]![ColName]", "ChildTabName",
"[MainID]=[ChildTabName]![MainTabID] And [ChildTabName]![ChildTabID]=
[SubformName].Form![ChildTabID] ")

Thanks in advance,
Ladi
 
A

Allen Browne

In a word, Don't.

Unless there are cases where the sum of values field in the main table
should validly be different from actual the sum of values in the related
table, you must not store this value.

If you want to do it anyway, use the AfterUpate and AfterDelConfirm events
of the subform to write the sum back to the parent form. The code will look
something like this:

Me.Parent![SomeControlName] = DSum("[ColName]", "ChildTabName", _
"[ChildTabID] = " & [ChildTabID])

If the field ChildTabID is a Text field, you need extra quotes:
Me.Parent![SomeControlName] = DSum("[ColName]", "ChildTabName", _
"[ChildTabID] = """ & [ChildTabID]) & """"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top