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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculation in Form

Status
Not open for further replies.

SJJB

IS-IT--Management
Mar 2, 2001
6
US
Need to get calculated total in Field 3
Formula is field2/field1

How would I do this so that once a person enters number into field2, field 3 automatically enters in the total from the calc.

Thanks in advance
 
You could do it in the After Update event of field2. Something like this.

Private Sub field2_AfterUpdate()

field3 = field2/field1

end sub

Hope that helps. :)
 
I have done the above, but am getting a variable not defined error. Is there something else I should do?
 
Doh!! Sorry about that.. Forgot to tell you to define the variables, or do it like tlbroadbent said..
 
While the offered soloution will generally work, I would almost never do it this way. Unless you are VERY careful re controls navigation, you WILL get an error from this.

In BOTH Field1 AND Field2 AfterUpdate events, call the (General) procedure basCalcField3()

Private Function basCalcField3
[tab]If (Me.Field1 = "") Then
[tab][tab]Exit Function
[tab]End If

[tab]If (Me.Field2 = "") Then
[tab][tab]Exit Function
[tab]End If

[tab]If (Val(Me.Field1) = 0) Then
[tab][tab]Exit Function
[tab]End If

[tab]'Do other / Additional Checks on the two Source fields'
[tab]'such as range (Field1 > NN) and (Field1 < NNN)

[tab]'Here ONLY if both fields pass ALL checks
[tab]Field3 = field1/field2
End Function

MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top