Solved

Adding fields on a Subform and getting results on the Mainform

Posted on 2014-12-17
6
119 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:SimonAdept
Comment Utility
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
Comment Utility
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
Comment Utility
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
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)

 
LVL 34

Accepted Solution

by:
PatHartman earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks!
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
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…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

744 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

16 Experts available now in Live!

Get 1:1 Help Now