By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,470 Members | 924 Online
Bytes IT Community
+ Ask a Question
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
Share this Question
Share on Google+
4 Replies


ADezii
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
  1. Private Sub txtCurrency1_AfterUpdate()
  2. If Not IsNull(Me![txtCurrency1]) And Not IsNull(Me![txtCurrency2]) Then
  3.   Me![txtCurrency3] = Format$(Me![txtCurrency1] + Me![txtCurrency2], "Currency")
  4. Else
  5.   'Remove any results from a previous calculation if either Field is blank
  6.   Me![txtCurrency3] = Null
  7. End If
  8. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtCurrency2_AfterUpdate()
  2. If Not IsNull(Me![txtCurrency1]) And Not IsNull(Me![txtCurrency2]) Then
  3.   Me![txtCurrency3] = Format$(Me![txtCurrency1] + Me![txtCurrency2], "Currency")
  4. Else
  5.   'Remove any results from a previous calculation if either Field is blank
  6.   Me![txtCurrency3] = Null
  7. End If
  8. 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
  1. Private Sub txtCurrency1_AfterUpdate()
  2. If Not IsNull(Me![txtCurrency1]) And Not IsNull(Me![txtCurrency2]) Then
  3.   Me![txtCurrency3] = Format$(Me![txtCurrency1] + Me![txtCurrency2], "Currency")
  4. Else
  5.   'Remove any results from a previous calculation if either Field is blank
  6.   Me![txtCurrency3] = Null
  7. End If
  8. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtCurrency2_AfterUpdate()
  2. If Not IsNull(Me![txtCurrency1]) And Not IsNull(Me![txtCurrency2]) Then
  3.   Me![txtCurrency3] = Format$(Me![txtCurrency1] + Me![txtCurrency2], "Currency")
  4. Else
  5.   'Remove any results from a previous calculation if either Field is blank
  6.   Me![txtCurrency3] = Null
  7. End If
  8. End Sub
i get the error msg sayin you cant assign a value to this object....
Mar 21 '07 #3

missinglinq
Expert 2.5K+
P: 3,532
Why not simply:

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtCurrency1_BeforeUpdate(Cancel As Integer)
  2.    Me![txtCurrency3] = Format$(Nz(Me![txtCurrency1]) + Nz(Me![txtCurrency2]), "Currency")
  3.  End Sub
  4.  
  5.  Private Sub txtCurrency2_BeforeUpdate(Cancel As Integer)
  6.    Me![txtCurrency3] = Format$(Nz(Me![txtCurrency1]) + Nz(Me![txtCurrency2]), "Currency")
  7.  End Sub
  8.  
Mar 21 '07 #4

P: 77
Why not simply:

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtCurrency1_BeforeUpdate(Cancel As Integer)
  2.    Me![txtCurrency3] = Format$(Nz(Me![txtCurrency1]) + Nz(Me![txtCurrency2]), "Currency")
  3.  End Sub
  4.  
  5.  Private Sub txtCurrency2_BeforeUpdate(Cancel As Integer)
  6.    Me![txtCurrency3] = Format$(Nz(Me![txtCurrency1]) + Nz(Me![txtCurrency2]), "Currency")
  7.  End Sub
  8.  

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

Post your reply

Sign in to post your reply or Sign up for a free account.