Solved

Adding fields on a Subform and getting results on the Mainform

Posted on 2014-12-17
6
120 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 33

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 34

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 33

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

862 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now