On Sun, 13 Jan 2008 09:48:01 -0800, s4 <(E-Mail Removed)> wrote:
>Hi, thanks for replying.
>I have a table called TABLEFB, which has fields DATEFB, AMOUNT1(-5) and TOTAL.
Then your table is designed incorrectly. You're using spreadsheet logic, and
Access is NOT a spreadsheet!
"Fields are expensive, records are cheap". If you have multiple amounts for a
given DATEFB then you should have *TWO TABLES* in a one to many relationship:
one with DATEFB as the primary key, together with any other information that
you need about that DATEFB; and a second table with one record - or five
records - or seven records - or however many records there need to be, with a
single AMOUNT field with one amount per record.
Also, the TOTAL field *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, either as a calculated field
in a Query or just as you're now doing it - in the control source of a Form or
a Report textbox.
>My report has DATEFB on the left, followed by each of the amounts and TOTAL
>at the end, and I'd like to have difference on the very right. These are
>grouped into weeks. At the group footer there's also a subtotal for each
>column (total for AMOUNT1, total for AMOUNT2 etc. using =sum[amountx] as
>control source).
>It's just getting the differece between TOTAL on say 03/01/2008 and
>27/12/2008 that I can't find a way to do.
That's because your data structure is wrong. It's really easy with a simple
Totals query if you use the properly normalized design above.
John W. Vinson [MVP]
|