Referring to controls from a subform

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kcdoell
    New Member
    • Dec 2007
    • 230

    Referring to controls from a subform

    Hello:

    I have read various posts on this subject but still can not get mine to work. Basically I have a Main form (Forecastform) with a subform (Forecast_Subfo rm). In the footer of the subform I have a unbound textbox (TGWP_Sub) that calculates a subtotal of the records that are displayed. In the main form I have another unbound text box (TGWP_Main) that I want to display the value of "TGWP_Sub" In the load event of the Main form I have the following code:

    [code=vb]
    Me.TGWP_Main = Me!Subform1.For m![TGWP_Sub]
    [/code]

    I am receiving an error message indicating that it can not find the control TGWP_Sub.

    My first question is:

    Am I missing something in my vb code.

    My second question is:

    Since my subtotal can change based on the records will the code in the load event be dynamic so that if changes are made, then my TGWP_Main control will display the latest calculation. If not, what would be the best approach to achieving that?

    Any assistance would be appreciated.

    Keith.
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Originally posted by kcdoell
    [code=vb]
    Me.TGWP_Main = Me!Subform1.For m![TGWP_Sub]
    [/code]
    Hi Keith. There is an error in your references. Your subform name is incorrect, unless it is renamed subform1 in your report.
    [code=vb]
    Me!TGWP_Main = Me!Forecast_sub form.Form![TGWP_Sub]
    [/code]

    A change to the calculated value on the subform total may need a form requery or refresh to be reflected back to the main form. Try it and see what happens. Form load event just fires once - no more, no less.

    -Stewart
    Last edited by Stewart Ross; Mar 20 '08, 09:11 PM. Reason: form name confusion, and second question answered

    Comment

    • kcdoell
      New Member
      • Dec 2007
      • 230

      #3
      Originally posted by Stewart Ross Inverness
      Hi Keith. There is an error in your references. Your subform name is incorrect, unless it is renamed subform1 in your report.
      [code=vb]
      Me!TGWP_Main = Me!Forecast_sub form.Form![TGWP_Sub]
      [/code]

      -Stewart

      Stewart I tried that and I got a message inside the TGWP_Main indicating that "this control has an invalid control source" (In design mode)

      When in view mode TGWP_Main is blank.

      Any ideas?

      Thanks for the reply.

      Keith.

      Comment

      Working...