Search code examples
ms-accessms-access-2000

Make default value on textbox triggered when other field change


So I have some textbox on my form,and on the last textbox, I turn off the enable so instead of asking the user for the input, I want to make the value on the textbox calculate automatically when the user input on another textbox, so I set the default value like this :

=IIf(IsNull([jmlh]),0,[jmlh]*[harga]*IIf([diskon]>0,[diskon],1))

But the problem is the expression just work when the form loaded, it's still not when value in "[jmlh]" change. Is there any method or something to make it possible?


Solution

  • Don't put your expression into Default Value, but into Control Source property.

    Then it will always update itself when one of the used fields changes.


    If it is a bound field (but why would you want a calculated field stored in the table?), you need to put that formula into a VBA function

    Private Function UpdateCalcField()
         Me.calcField = IIf(IsNull([jmlh]),0,[jmlh]*[harga]*IIf([diskon]>0,[diskon],1))
    End Function
    

    and call that function from the AfterUpdate events of all involved fields.