Forum Discussion

Tony2021's avatar
Tony2021
Steel Contributor
Mar 17, 2022
Solved

Refresh Sum in form

Hello Experts,

 

I have a form in datasheet. 

There is a sum in one of the columns (I used the sum button and choose "sum" in the combo box in the record below)

When I change a value in the record, the sum doesnt change until I click on another record.  

 

How can I make the sum change when I update a field on the record? 

 

I thought the below would work:

Private Sub Form_AfterUpdate()

Me.Refresh
Me.Recalc
'doesnt refresh the summation though

End Sub

  • Changes to records are not saved until you move off that record or click Enter (which has the same effect). That behaviour is by design in Access databases.

    Your code will not work - the form has not been updated whilst you remain on the record.
    Once you leave the record, the update occurs automatically with no need to requery, recalc, refresh or even repaint!



11 Replies

  • George_Hepworth's avatar
    George_Hepworth
    Silver Contributor

    Tony2021 As Colin pointed out, you don't need to do anything except move focus to another record. However, if you have a business need to see the updated sum without moving to a new record, you can force the save by adding:

     

    Me.Dirty = False

     

    to your code before refreshing the form.

    • Tony2021's avatar
      Tony2021
      Steel Contributor

      George_Hepworth 

      Hello, thank you for the response.

      I understand that maybe this cant be done.
      George, I tried Me.Dirty as instructed but it still did not refresh teh sum.  I also tried to save the record. i also added it to the form's On Dirty Event. 

       

      Let me know if any other suggestions or if I should forget about this.  

       

       

       

      • arnel_gp's avatar
        arnel_gp
        Steel Contributor
        on the "Column" you are Totalling, add code to it's AfterUpdate event to force save the record.

        private sub theColumnName_AfterUpdate()
        Me.Dirty = False
        end sub
  • Changes to records are not saved until you move off that record or click Enter (which has the same effect). That behaviour is by design in Access databases.

    Your code will not work - the form has not been updated whilst you remain on the record.
    Once you leave the record, the update occurs automatically with no need to requery, recalc, refresh or even repaint!



Resources