Click to See Complete Forum and Search --> : Multiplying Field Values
johnpc
Jul 10th, 2000, 04:44 PM
Given a simple Access DB Table with the following:
Item UnitPrice Qty
Muffler $28.00 3
Horn $10.00 2
Is it possible for or in VB to create a fourth field "Totals" that multiplys the values of UnitPrice times Qty and places the results there, i.e.,
Item UnitPrice Qty Totals
Muffler $28.00 3 $84.00
Horn $10.00 2 $20.00
Tonatiuh
Jul 10th, 2000, 05:40 PM
I can't figure out exactly what you want. Could you be more explicit? do you have any code segment that want to be better?
CGTS
Jul 10th, 2000, 09:14 PM
You can do this in one of two ways. Firstly you could create a query at the database level that created the new field based on the calculation, or alternatively through VB you could open a recordset with the same SQL and as with the previous way it creates a dynamic field for your use.
The SQL for the query would be
SELECT tblParts.Item, tblParts.Quantity, tblParts.Cost, [quantity]*[cost] AS Total
FROM tblParts
You can see here that we create a field by the code[quantity]*[cost] AS Total
So when you open the recordset you will have access to all four fields (Item,Quantity,Cost,Total) just like a table.
johnpc
Jul 11th, 2000, 05:48 AM
Thanks CGTS, this is what I was looking for
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.