Solved

Adding fields on a Subform and getting results on the Mainform

Posted on 2014-12-17
6
122 Views
Last Modified: 2014-12-18
I am inputting numbers on the subform but want the results on the main form..how do I do that?
0
Comment
Question by:Jass Saini
6 Comments
 
LVL 18

Expert Comment

by:Simon
ID: 40505812
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:
       =Me!Subform1.Form!ControlName

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
me.parent.requery
if the subform is bound to data that the main form is also based on.
0
 

Author Comment

by:Jass Saini
ID: 40505963
I am still unclear.  I would like the sum of the field from the subform in a textbox on the mainform
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40506235
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
      rs.MoveFirst
      Do Until rs.EOF
        total = total + Nz(rs!ValuesToEdit)
      rs.MoveNext
    Loop
    End If
    Parent!txtSum.SetFocus
    Parent!txtSum.Text = total
    
End Sub

Private Sub Form_AfterUpdate()
   UpdateSum
End Sub

Private Sub Form_Current()
   UpdateSum
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
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 35

Accepted Solution

by:
PatHartman earned 500 total points
ID: 40506350
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
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40506362
Pat,

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.

Mike
0
 

Author Closing Comment

by:Jass Saini
ID: 40507753
Thanks!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question