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

Sum FUNCTION doesn't work with non table Text Box?

Status
Not open for further replies.

MarkoKobal

IS-IT--Management
Jul 18, 2001
14
SI
I have an Text Box, wich calculates an formula for each row in table, althought it's not a table element. Can I use Sum function on that only displayed numbers?
 
Yes, assuming I understand what you are asking!
just refer to the name of the textbox in the formula.

=Text1 + Text2

if text1 held the sum of dollars and text2 held the count of records this would give the average

=Text1 / Text2
 
Actualy thats not it. I have an tabele with:
(ITEM, PRICE, QUANTITY, DISCOUNT)
An on form I have for each row a TextBox that calculates price*quantity+pisqount. And that works OK, but if I want to make a TextBox at the end wich sumarizes all the final prices in calclated TextBox, how do I do this (the simple Sum() function doesn't work.
 
Sorry I misunderstood what you were attempting.
=Sum([price]*[quantity]+[discount]) should work in this instance.
What problems are you having with the sum function is it returning the incorrect sum or what?
Also I am assuming you are doing this on a continous form.
 
A text box won't do what you want. Here's two ways to accomplish this.

(1)If your form is based on a table you must create another field in your table, say "Total".
table1 = table name, p=price, q=quantity, d=discount, and t=total. In the "AfterUpdate" event for each field...p,q, and d...write code like this.

Dim t As Control
Set t = Forms![Table1]![t]
t = DSum("(([p]*[q])-(([p]*[q])*[d]))", "Table1")
Form.Refresh

This will calculate t each time you enter or change a value.

(2)If your form is based on a query then create a new field in the query, like "Total". In the field line write something this:

Total: (([p]*[q])-(([p]*[q])*[d]))

Either way will solve your problem.

Dan Rogotzke
Dan_Rogotzke@oxy.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top