Solved

Adding fields on a Subform and getting results on the Mainform

Posted on 2014-12-17
6
124 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 38

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

717 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