Calculating Extended Price

S

serviceenvoy

I think what I need to do is very simple but everything I've read
online just confuses me.
Fields: Quantity, Cost, Total
All fields are on the same form
I need to create an expression that will calculate the extended price
by multiplying "QUANTITY" by "COST" and displaying the results in the
"TOTAL" field. How do I do this?
 
A

Al Campagna

service,
Add an unbound calculated text control to the form with a controlsource of...
= Quantity * Cost
That will always "display" the correct Total, and will recalculate whenever Quantity or
Cost is changed.

--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."
 
C

Carl Rapson

I think what I need to do is very simple but everything I've read
online just confuses me.
Fields: Quantity, Cost, Total
All fields are on the same form
I need to create an expression that will calculate the extended price
by multiplying "QUANTITY" by "COST" and displaying the results in the
"TOTAL" field. How do I do this?

In the AfterUpdate events of both the Quantity and Cost controls, do your
calculation. You may need to use the Nz function in case one or the other
hasn't been entered yet. Something like:

Public Sub Quantity_AfterUpdate()
Total = Nz(Quantity,0) * Nz(Cost, 0)
End Sub

Public Sub Cost_AfterUpdate()
Total = Nz(Quantity,0) * Nz(Cost, 0)
End Sub

Of course, this doesn't contain any error checking (were valid numbers
entered for Quantity and Cost?). And, if all three controls (Quantity, Cost,
Total) are bound to fields in a table or query, you might want tore-think
your design. Since the Total can be calculated at any time from the Quantity
and Cost, there's no need to store it in the database.

Carl Rapson
 
S

serviceenvoy

In the AfterUpdate events of both the Quantity and Cost controls, do your
calculation. You may need to use the Nz function in case one or the other
hasn't been entered yet. Something like:

Public Sub Quantity_AfterUpdate()
Total = Nz(Quantity,0) * Nz(Cost, 0)
End Sub

Public Sub Cost_AfterUpdate()
Total = Nz(Quantity,0) * Nz(Cost, 0)
End Sub

Of course, this doesn't contain any error checking (were valid numbers
entered for Quantity and Cost?). And, if all three controls (Quantity, Cost,
Total) are bound to fields in a table or query, you might want tore-think
your design. Since the Total can be calculated at any time from the Quantity
and Cost, there's no need to store it in the database.

Carl Rapson

THANKS TO BOTH OF YOU.

Now, how do I make the results look like currency? i.e. $12.00
instead of 12?
 
S

serviceenvoy

service,
= Format(([Quantity] * [Cost]), "$ #.00")

--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVPhttp://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."


THANKS TO BOTH OF YOU.
Now, how do I make the results look like currency? i.e. $12.00
instead of 12?

Perfect. You guys are incredible. You don't know how much you've
helped me with these simple things.
 
M

Marryam Murtaza

hello



serviceenvo wrote:

Calculating Extended Price
20-Apr-07

I think what I need to do is very simple but everything I've rea
online just confuses me
Fields: Quantity, Cost, Tota
All fields are on the same for
I need to create an expression that will calculate the extended pric
by multiplying "QUANTITY" by "COST" and displaying the results in th
"TOTAL" field. How do I do this?

EggHeadCafe - Software Developer Portal of Choice
WPF DataGrid Custom Paging and Sorting
http://www.eggheadcafe.com/tutorial...f-32b2d802ae17/wpf-datagrid-custom-pagin.aspx
 
G

Gina Whipp

Marryam ,

To DISPLAY the total... in the Total field put...
+Nz([Quantity],0)*Nz([Cost],0)

Should you want to store that value you would need to put the above in the
After_Update event procedure of the Quantity field and the Cost field.

Also note, if those are not the sam names as your fields, adjust
accordingly.

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top