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 GET A FIELD TO UPDATE AFTER CALCULATION

Status
Not open for further replies.

Lightningfast

Technical User
Jul 27, 2002
18
AU
I am running a calculation based on field called weight and want to return a,b,c or d to a field called weightcode automatically. This is the code I put in the weightcode field. =IIf([weight]<=170,&quot;a&quot;,IIf([weight]>170 And [weight]<=420,&quot;b&quot;,IIf([weight]>=420 And [weight]<670,&quot;c&quot;,&quot;d&quot;)))
This works fine but does not update the data in weightcode.
What am I doing wrong,
Thanks Trevor
 
That's because your WeightCode field is a calculated control, which only shows the result of a real-time calculation.
And actuallt this is what should happen. It's a baaaad idea to store results that you can always retrieve by a calculation formula.

However, if you really want to store it, bind the control to the field (in the Properties-Control source, select WeightCode). Then paste the following sub in the General section of the form's code.
Call the procedure from whatever event suits you (probably AfterUpdate event of Weight control would be just fine)

Sub UpdateWeightCode()
WeightCode = IIf([weight]<=170,&quot;a&quot;,IIf([weight]>170 And [weight]<=420,&quot;b&quot;,IIf([weight]>=420 And [weight]<670,&quot;c&quot;,&quot;d&quot;)))
End Sub

Sub Weight_AfterUpdate()
UpdateWeightCode
End Sub

Dan
[pipe]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top