acss said:
I have two tables, one for Invoices which contain fields such as InvID-PK,
Inv description, date, Reference. Then i have an Invoice Details table,
DetailId-PK, InvID-FK, Detail Description, InvAmt. Not all invoices have 3
line items that add up to the total amount so while some records will have
detail amounts others will be blank and only a totals amount would be in the
InvAmt. Should i have a named field for each line item that will lead up to
the total? Also should i have an InvAmt in the Invoice Table and InvDetails
table as well?
Your table definitions sound correct to me. I don't follow some of what
you've written: ".. only a totals amount would be in the InvAmt".
This is how I approached a similar situation, with unnecessary details
omitted:
I have a table of customers. I have a table of "Goods and Services
supplied", and another of "workperiods". So if I spend half an hour
installing some network card, which I've supplied, this customer will
have a record in each. The tables are related one Customer to many
"Goods..." and to many "WorkPeriods". I have a form which allows
convenient data entry when I've done some work.
When it comes to invoicing, I have a main form of customer records. I
use a combo box on the customer-ID field to trigger (using an Event
handler in VBA) a filter to the selected customer only.
On the form I have two subforms, linked by Customer-ID, displaying
"Goods..." and "WorkPeriods" respectively. Each displays however many
records there happen to be for that customer. Sometimes there are none,
so it simply shows a line for a new record (pretty sure you can stop
this, but I've never bothered). In each subform's footer, I have a
(hidden) text box whose control source sums the appropriate field of
records displayed in the subform. On the main form, just under the
subform, I have another text box, not hidden, which refers to the
corresponding text box on the subform. This is done so that a further
text box at the bottom of the main form can total the subform-totals.
So, having selected/filtered a particular customer, the Grand Total box
shows the total of the two "subtotal" boxes, each of which get their
value from a total of the subform's displayed records. (Phew - hope you
follow this!).
So, to (finally) answer your questions:
No, you shouldn't have a named field in the Invoices table for each
line-item. You store the foreign key at the other end of the
relationship. Line-items are records in a separate table, related to
the Invoice by a field in the line-item which stores the Invoice's key.
Note that I've done this differently. I invoice some customers only
monthly so the more important relationship is between customer and
line-item: the Invoice is filled in later when the invoice is generated.
No, you shouldn't store the InvAmt in two places. You can always derive
the Invoice total from the line-items.
Phil