views:

164

answers:

1

How do I get two tables of their values to add up into one table record, e.g.

Item table:

ID - Autonumber

OrderID - Number

Price - Currency

Details - Text

Order table:

ID - Autonumber

CustomerID - Number

Date - Date

TotalPrice - Currency

The TotalPrice should add up all the items and the total price of adding them up into the TotalPrice which would be collected as a record value.

+1  A: 

If you want to total up a column of data using SQL syntax in Access you should use the SUM keyword with GROUP BY.

In your case use this something like this:

SELECT o.ID, o.CustomerID, o.Date, SUM(i.Price)
FROM Order AS o
LEFT JOIN Item AS i
ON i.OrderID=o.ID
GROUP BY o.ID, o.CustomerID, o.Date

If you wish to store that column in the Order table then you would still use the above syntax (or similar) to calculate it.

How you use this inside Access depends on you. You could store this as a named query and make the query the Record Source for a Datasheet. Or you can load this sql directly into the Record Source of a Datasheet. Or a Single Form.

hawbsl
How do I get msaccess to excute the query?
Wayne
Ok... I have my form, but in this text field I can't find the part where it should execute the sql query :S The text field should show the total price, appreciate the more help :-)
Wayne
what's the recordsource of the form?
hawbsl
What's a Recordsource?
Wayne
The Recordsource is listed in the Properties of your form, on the Data tab
hawbsl