Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I return values after calculation?

Status
Not open for further replies.

tech4ultimate

Technical User
Jul 2, 2003
19
US
I have 3 text boxes on my form.labeled as follows
Amount($) , Rate(%) and Returns($).By goal is to automatically display a value in the third box after any of the other two boxes are updated.
For example if Amount has 100 and Rate is 25 then 125 will display in Returns.My goal is to be able to get the correct results irrespective of the order in which the boxes are updated so if i updated Rate with 25 then Returns with 125 Amount should display 100.
My coding only works if my update begins with Rate if any other box is updated first they all return a null value.
Much appreciation for any help received.

Below is the code i am using:

Private Sub Amount_AfterUpdate()
[Rate] = ([Returns] - [Amount]) / (0.01 * [Amount])
[Returns] = [Amount] + (0.01 * [Rate] * [Amount])
End Sub

Private Sub cmdClear_Click()
[Rate] = Null
[Returns] = Null
[Amount] = Null
End Sub

Private Sub Form_Load()
[Rate] = Null
[Returns] = Null
[Amount] = Null
End Sub

Private Sub Rate_AfterUpdate()
[Returns] = [Amount] + (0.01 * [Rate] * [Amount])
[Amount] = [Returns] - (0.01 * [Rate] * [Amount])
End Sub

Private Sub Returns_AfterUpdate()
[Rate] = ([Returns] - [Amount]) / (0.01 * [Amount])
[Amount] = [Returns] - (0.01 * [Rate] * [Amount])
End Sub
 
Unless I've forgotten my algebra, I don't know how you could find the Returns with just the Rate and no Amount. My suggestion is to make the Return field properties Enabled to NO and Locked to YES and then

Code:
Private Sub Amount_AfterUpdate()
    Me.Returns = [Amount] + (0.01 * [Rate] * [Amount])
End Sub

Private Sub Rate_AfterUpdate()
    Me.Returns = [Amount] + (0.01 * [Rate] * [Amount])
End Sub

Or you could leave the Enabled and Locked as is and try this:

Code:
Private Sub Amount_AfterUpdate()
    If IsNull(Amount) And Not IsNull(Rate) Then
        Me.Returns.Enabled = False
    Else
        Me.Returns.Enabled = True
    End If
    
    Me.Returns = [Amount] + (0.01 * [Rate] * [Amount])
End Sub

Private Sub Rate_AfterUpdate()
    If IsNull(Amount) And Not IsNull(Rate) Then
        Me.Returns.Enabled = False
    Else
        Me.Returns.Enabled = True
    End If

    Me.Returns = [Amount] + (0.01 * [Rate] * [Amount])
End Sub

Private Sub Returns_AfterUpdate()
    Me.Rate = ([Returns] - [Amount]) / (0.01 * [Amount])
End Sub

Hope that helps.

Debbie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top