Forum Discussion

Storming's avatar
Storming
Brass Contributor
Apr 03, 2020

Refreshing calculated controls

I have an unbound form which has on it 3 calculated controls and a subform based on a query on an accounts transactions table.

On opening the form the 3 controls are calculated from data from the subform query.

I want to refresh the 3 calculation controls whenever data is amended/added/deleted in the subform and I want to also refresh the 3 calculation controls if the subform is filtered.

All suggestions would be welcome as to how I can achieve this.

  • Storming You can use the AfterUpdate events of the controls in the subform. 

     

    Because you want to call the same requery from multiple controls, you'd probably best make it a separate sub that can be called from those control events. Something like this, using your own control names, of course.

     

    Public Sub RefreshMainForm()

     

         With Me

              .Parent.FirstUnboundControlNameGoesHere.Requery

              .Parent.SecondUnboundControlNameGoesHere.Requery

              .Parent.ThirdUnboundControlNameGoesHere.Requery

          End With

     

    End Sub

    • Storming's avatar
      Storming
      Brass Contributor

      George Hepworth 

       

      Hi George, many thanks for that but....

       

      The calc controls are based on the following code when the form is loaded:-

       

      [Forms]![Accounts open maintenance]![Tot Gross] = DSum("[Gross Amount]", "Accounts open query", "[Type]='Income'") - DSum("[Gross Amount]", "Accounts open query", "[Type]='Expenditure'")

       

      How do I reset the control to the filtered data?

      • George Hepworth's avatar
        George Hepworth
        Steel Contributor

        Call that code by referring to the Open Form sub. You'll have to change it from a Private to a Public Sub

         

         

        OR, move that code to the public sub as described above. 

         

         

Resources