Adding fields on a Subform and getting results on the Mainform

I am inputting numbers on the subform but want the results on the main do I do that?
Jass SainiAsked:
Who is Participating?
PatHartmanConnect With a Mentor Commented:
Add a footer to the subform.
Add controls to sum the subform data.
It isn't necessary for the footer to be visible or for the controls to be visible.
On the mainform, add a control to show the sum from the subform.
Make its ControlSource = SubformName!txtSum
You can have calculated fields on the main form that refer to the subform.
This is a good reference for the subject.
The one you want is:

You can refer to totals in the footer of the subform using this method, or you can have a button on the subform that does something like
if the subform is bound to data that the main form is also based on.
Jass SainiAuthor Commented:
I am still unclear.  I would like the sum of the field from the subform in a textbox on the mainform
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Mike EghtebasDatabase and Application DeveloperCommented:
I am inputting numbers on the subform...

It seems your are saying, your subform is continuous type where the values in a certain field can be edited. Based on this assumption you can try the following.

Let's say the name of this text box in the subform is txtValuesToEdit (with matching field name of ValuesToEdit in its table). From the Private Sub Form_AfterUpdate() event of  the subform fire UpdateSum  shown below (assuming the main form is also has txtSum on it):

Private Sub UpdateSum()

    Dim rs As DAO.Recordset
    Dim total As Variant
    Set rs = Me.RecordsetClone
    If rs.RecordCount > 0 Then
      Do Until rs.EOF
        total = total + Nz(rs!ValuesToEdit)
    End If
    Parent!txtSum.Text = total
End Sub

Private Sub Form_AfterUpdate()
End Sub

Private Sub Form_Current()
End Sub

Open in new window

Also, add UpdateSum to Private Sub Form_Current() of the subform so that upon opening the form it would show the total amount.

Mike EghtebasDatabase and Application DeveloperCommented:

ControlSource = SubformName!txtSum was the key I missed.

First I started using sum in the subform footer pushing it to the parent form but there was sort the delaly (it showed older sum not the most recent).

With your solution, I think there is a need to have Parent.Refresh in the after update event of text box being edited. hopefully it will work then.

It is possible, your solution also have the delay problem.

Jass SainiAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.