View Full Version : Auto Calculate Fields


MaaaTTY
10-07-2009, 10:51 AM
Ok so heres the deal:

i have a price value in 1 table and a quantity value in another.

i want to make a totals value(price * quantity) inside the 2nd table with the quantity value.

i made a query but i really have no idea if i did it right or what to do from there. when i look at my query in data view it shows:

1. a price column with all values,
2. a quantity column with all correct values
3. and a TotalValue column with all the correct calculations made


but i want that TotalValue column to show up in my table not just the query.

What do i need to do to make this work?

Thanks in advance!

boblarson
10-07-2009, 11:00 AM
1. Due to rules of normalization (http://support.microsoft.com/kb/283878), you do NOT store calculated fields in your table if you have the data to recreate the calculation at runtime, which it appears you do.

2. This has to do with the fact that you cannot guarantee that your data will be correct if someone goes into one of the tables and makes a change to one of the pieces that make up that calculation. (in Access 2010 we will have data macros and calculated field types which will ensure this, but at this point it is still a big no, no to store this).

You display the totals using a QUERY.

MaaaTTY
10-07-2009, 11:03 AM
i am using a query? am i not? how do i do this then without breaking the rules of normalization?

boblarson
10-07-2009, 11:06 AM
i am using a query? am i not? how do i do this then without breaking the rules of normalization?
Continue to use the query whenever you need the values. In fact you can have a "base query" created where you use that instead of the table when you, or anyone else, needs the calculated values. (remember you can use a query in 99.99% of the places you use a table)

MaaaTTY
10-07-2009, 11:14 AM
so you just mean i can run the query and use the calculated values to view or manually enter the results, but i can not use it to automatically fill in the fields for me? sorry im just very new and really dont understand the concept of a query.

boblarson
10-07-2009, 11:27 AM
Okay, you can't change calculated values in a query. Depending on how the query is set up you might be able to change the values that make up the calculation.

A query is the mainstay of a database. It is actually a query you see when you open a table. You never really see a table directly, but a query that brings data back from the table. I think you might benefit from reading this (http://www.functionx.com/access/Lesson21.htm).

MaaaTTY
10-07-2009, 11:29 AM
kk, Thanks :P