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

Simple Addition

Status
Not open for further replies.

Ali29J

Technical User
Joined
May 13, 2004
Messages
203
Location
GB
Simple one for ya,

I have an on click event which is simply designed to do add together 4 record sources

=[CostPlusfreight]=[FreightCost]+[InsuranceCost]+[HaulageCost]+[Cost]

But when I press it does not add, can anyone offer any guidance?

For example, i get 1+1+1+1=1111, where as I am trying to get 4, what am I doing wrong?

I know simple for you guys in the know
 
It seems they are perceived as text (is the datatype of the fields they are bound to, text?), try for instance something like this:

[tt][CostPlusfreight]=val([FreightCost])+val([InsuranceCost])+val([HaulageCost])+val([Cost])[/tt]

Should there be possible Null values, too, then perhaps also use the Nz function in addition. BTW - you don't add control sources (which often are fields), you add the value of the control for the current record, and I often prefer to rename the controls so they don't have the same name as the controlsource, for instance, txtCostPlusFreight, txtCost...

Roy-Vidar
 
THanks Roy, taken your suggestion of the Nz function also worked like a dream,

One further thing, I currently use a command button to calculate, but when pressed it will only update current line in a continuous form, is there any way to update all linked fields (currently continuous form is a aubform and only shows linked data), or even to update the result as numbers are entered, not really sure of best way to approach this
 
Had it been a controlsource of a control, then issuing:

[tt]me.recalc[/tt]

should do. Placing the code in the after update event of the controls it is dependent of, and the on current, should be some steps in the right direction, but I don't think it would calculate for rows you "haven't visited".

If not then perhaps use an update query or loop thru the form recordset provided the "total" is a field in the recordsource - which it btw shouldn't be, since it's calculated and can be derived from other fields in the recordsource -> calculate in the control source of the "total" control;-)

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top