You shouldn't store calculated values. As fellow MVP John Vinson likes to
say, "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. "
Use a query to calculate the total. The SQL would be something like:
SELECT VendorID, [Vendor Name], [Vendor Address], Count(*) AS NumberChecks
FROM tblVendor INNER JOIN tblPayments
ON tblVendor.VendorID = tblPayments.VendorID
GROUP BY VendorID, [Vendor Name], [Vendor Address]
Use that query anywhere you would otherwise have used tblVendor.
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"adna" <(E-Mail Removed)> wrote in message
news:F6F614FB-E27C-491A-AB5D-(E-Mail Removed)...
>I have a form frmVendors with a subform frmPayments. The main form shows
> information on vendors, and the subform is a continuous form which lists
> the
> checks paid out to each vendor. Users are typically entering new payments
> into the subform on the main form.
>
> The forms are linked to tables: Linked by VendorID (one to many)
> tblVendor: Key=VendorID, Vendor Name, Vendor Address, Vendor State,
> Vendor
> City
> tblPayments: Key=CheckID, VendorID, PaymentAmount
>
> There is a field in tblVendor called NumberChecks to show the total amount
> of checks paid out to that vendor. There is a text box on the main form
> to
> show NumberChecks. Right now, the user must increment NumberChecks
> manually
> when they add a new payment amount.
>
> I need a way to count the number of checks for each VendorID in
> tblPayments,
> and store it in tblVendors in the NumberChecks field. I also want the
> NumberChecks field on frmVendors to update when a new payment is added or
> if
> a payment is deleted.
> Any Ideas?
>