429,470 Members | 924 Online
Need help? Post your question and get tips & solutions from a community of 429,470 IT Pros & Developers. It's quick & easy.

# calculation

 P: 77 i have to fields in a form which are both currency field types.. what i need is the sum of both fields to be displayed automatically in a third field.. can anyone help Mar 21 '07 #1
4 Replies

 Expert 5K+ P: 8,627 i have to fields in a form which are both currency field types.. what i need is the sum of both fields to be displayed automatically in a third field.. can anyone help Assumptions: __1. Field #1: txtCurrency1 __2. Field #2: txtCurrency2 __3. Field #3: txtCurrency3 In the AfterUpdate() Event of both txtCurrency1 and txtCurrency2, place the following code: Expand|Select|Wrap|Line Numbers Private Sub txtCurrency1_AfterUpdate() If Not IsNull(Me![txtCurrency1]) And Not IsNull(Me![txtCurrency2]) Then   Me![txtCurrency3] = Format\$(Me![txtCurrency1] + Me![txtCurrency2], "Currency") Else   'Remove any results from a previous calculation if either Field is blank   Me![txtCurrency3] = Null End If End Sub Expand|Select|Wrap|Line Numbers Private Sub txtCurrency2_AfterUpdate() If Not IsNull(Me![txtCurrency1]) And Not IsNull(Me![txtCurrency2]) Then   Me![txtCurrency3] = Format\$(Me![txtCurrency1] + Me![txtCurrency2], "Currency") Else   'Remove any results from a previous calculation if either Field is blank   Me![txtCurrency3] = Null End If End Sub Mar 21 '07 #2

 P: 77 Assumptions: __1. Field #1: txtCurrency1 __2. Field #2: txtCurrency2 __3. Field #3: txtCurrency3 In the AfterUpdate() Event of both txtCurrency1 and txtCurrency2, place the following code: Expand|Select|Wrap|Line Numbers Private Sub txtCurrency1_AfterUpdate() If Not IsNull(Me![txtCurrency1]) And Not IsNull(Me![txtCurrency2]) Then   Me![txtCurrency3] = Format\$(Me![txtCurrency1] + Me![txtCurrency2], "Currency") Else   'Remove any results from a previous calculation if either Field is blank   Me![txtCurrency3] = Null End If End Sub Expand|Select|Wrap|Line Numbers Private Sub txtCurrency2_AfterUpdate() If Not IsNull(Me![txtCurrency1]) And Not IsNull(Me![txtCurrency2]) Then   Me![txtCurrency3] = Format\$(Me![txtCurrency1] + Me![txtCurrency2], "Currency") Else   'Remove any results from a previous calculation if either Field is blank   Me![txtCurrency3] = Null End If End Sub i get the error msg sayin you cant assign a value to this object.... Mar 21 '07 #3

 Expert 2.5K+ P: 3,532 Why not simply: Expand|Select|Wrap|Line Numbers Private Sub txtCurrency1_BeforeUpdate(Cancel As Integer)    Me![txtCurrency3] = Format\$(Nz(Me![txtCurrency1]) + Nz(Me![txtCurrency2]), "Currency")  End Sub    Private Sub txtCurrency2_BeforeUpdate(Cancel As Integer)    Me![txtCurrency3] = Format\$(Nz(Me![txtCurrency1]) + Nz(Me![txtCurrency2]), "Currency")  End Sub   Mar 21 '07 #4

 P: 77 Why not simply: Expand|Select|Wrap|Line Numbers Private Sub txtCurrency1_BeforeUpdate(Cancel As Integer)    Me![txtCurrency3] = Format\$(Nz(Me![txtCurrency1]) + Nz(Me![txtCurrency2]), "Currency")  End Sub    Private Sub txtCurrency2_BeforeUpdate(Cancel As Integer)    Me![txtCurrency3] = Format\$(Nz(Me![txtCurrency1]) + Nz(Me![txtCurrency2]), "Currency")  End Sub   i get the following msg "the value u entered isnt valid for this field".. on the following line of code... Private Sub Combo86_AfterUpdate() Me![totalcost] = Format\$(Nz(Me![Combo86]) + Nz(Me![Combo84]), "Currency") End Sub Mar 22 '07 #5