How do I get a total to refresh in my Form from a Subform

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jinzuku
    New Member
    • Feb 2011
    • 12

    How do I get a total to refresh in my Form from a Subform

    Hi,

    I've created a main form that populates a subform using 2 combo boxes, however I'm having difficulty trying to create a sum of the total amounts of the results of the population.

    I have a Grand_Total field in my form that the subform is based on.

    In my main form if I try to reference to the Grand_Total in the form my subform is based on then I get a #Name? error (=forms![form]![Grand_Total) and if I try to calculate it myself it comes up with a #Error (=sum(forms![form]![Amounts])).

    Using the reference the only way I can get it to work is to populate the subform, open the form the subform is based on and then click into the subform in my main form. Obviously, that is longwinded and was hoping if there was a way of making it automatic when I click my command button that populates the subform.

    Sorry if that's hard to understand, i usually don't explain things very well

    Sunny
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32636

    #2
    The sub-form has a .Parent property that points to the SubForm control of the main form. You can reference it that way. If you need further help with how the two forms (Main and Sub) are related to each other then see Referring to Items on a Sub-Form.

    Comment

    • Jinzuku
      New Member
      • Feb 2011
      • 12

      #3
      Sorry for being dumb but I don't really understand how it gets my to display the total of the data in the subform. Would any other information be useful? I'm reletively new to Access and have vitrually no knowledge of VBA.

      I tried looking that your other article but it just went over my head.

      Comment

      • Jinzuku
        New Member
        • Feb 2011
        • 12

        #4
        Sorry again but I think I've sorted it out based on what I could understand from your suggestion. I replaced the coding in my text box to "=Forms![Main Form]![Subform]![Grand_Total]" and that has seemed to work.

        Thanks for your help

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32636

          #5
          Once you have a reference to the relevant form, you can use .Refresh or .Requery to update the data on the form from the underlying tables. .Requery is required in place of .Refresh only when underlying records have been added or removed.

          Comment

          Working...