Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Adding fields on a Subform and getting results on the Mainform

Posted on 2014-12-17
6
Medium Priority
?
127 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 39

Accepted Solution

by:
PatHartman earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

610 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