View Single Post
  #3  
Old March 21st, 2010, 09:39 PM posted to microsoft.public.access.tablesdbdesign
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Getting a total in $

On Sun, 21 Mar 2010 08:34:01 -0700, Rob H
wrote:

I have a table with a Gross Sales field and a Total Costs field, there is a
third field called Net Sales. How can I create a function to take Gross
Sales minus Total Costs to populate the Net Sales field? All three are set
to currency.


You don't.

The net sales should SIMPLY NOT EXIST in your table.

Storing derived data such as this in your table accomplishes
three things: it wastes disk space; it wastes time (almost
any calculation will be MUCH faster than a disk fetch); and
most importantly, it risks data corruption. If one of the
underlying fields is subsequently edited, you will have data
in your table WHICH IS WRONG, and no automatic way to detect
that fact.

Just redo the calculation whenever you need it; you can do so in a Query by
putting an expression like

NetSales: [Gross Sales] - [Total Costs]

in a vacant Field cell in the query, or on a Form or Report by putting

=[Gross Sales] - [Total Costs]

as the Control Source of a textbox.
--

John W. Vinson [MVP]