Counting Number Records per Unique ID, saving it to another table:

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?

0
Utf
11/5/2007 4:47:08 PM
access 16762 articles. 3 followers. Follow

4 Replies
963 Views

Similar Articles

[PageSpeed] 19

Stop storing the "number of checks"!  This value can be derived using a 
simple Totals query, or by using the DCount() function.

That way, no one needs to remember to update the field.

Regards

Jeff Boyce
Microsoft Office/Access MVP

"adna" <adna@discussions.microsoft.com> wrote in message 
news:F6F614FB-E27C-491A-AB5D-66BC8F7C556D@microsoft.com...
>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?
> 


0
Jeff
11/5/2007 4:57:53 PM
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" <adna@discussions.microsoft.com> wrote in message 
news:F6F614FB-E27C-491A-AB5D-66BC8F7C556D@microsoft.com...
>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?
> 


0
Douglas
11/5/2007 4:58:15 PM
if your subform is filtered to contain only checks for a single vendor you 
can use the recordcount property of its recordset object to get the number of 
checks for that vendor.

Or you could write a VBA function to open a recordset, run some SQL 
statement, and return the record count of the recordset.  Pretty much the 
same effect, but wouldn't require the subform to be filter.. or even be open.


"adna" wrote:

> 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?
> 
0
Utf
11/5/2007 5:09:00 PM
Hi all,
Thanks for the advice.  No one ever told me not to store calculated fields 
(i'm self taught) but it does make sense.  I had been working on a solution 
where I had a hidden field txtCheckCount on the subform with control source 
=Count([PaymentAmount]).
Then on the main form I had an unbound field with control source 
=Forms!frmVendor![frmPayment]!txtCheckCount

This was working to show the number of checks but I wasn't able to store it 
in the database.  Now I will simply take the NumberChecks field out of 
tblVendor calculate the value where needed.

Thanks!

"adna" wrote:

> 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?
> 
0
Utf
11/5/2007 5:54:01 PM
Reply:

Similar Artilces:

number rounding in MS Excel
Hi, This may have been answered many times. In MS EXCEL is there a way that it calculates all numbers to 2 decimal digit accuracy instead of the 15 digit default? Thanks in advance for the answer. Hi You can set your decimal places in your cells as 2 and then check Precision As Displayed on the Tools / Options / Calculation page. Be careful though, it means what it says!! -- Andy. "mahusain" <abidh@bdnet.net> wrote in message news:ab59c6f6.0404200315.5196e8aa@posting.google.com... > Hi, > > This may have been answered many times. > > In MS EXCEL is ther...

incorrect check / cheque number printing
When generating a cheque run, let’s say cheque 61, 62, 63 and 64, the information printed on cheque # 62 is actually cheque # 64 and vice versa. This does not happen every cheque run, but it does happen fairly often. I have not seen GP do this. What version and service pack of GP are you using? Are you 100% sure the check stock itself is not out of sequence? Do you have any customizations? -- Victoria Yudin Dynamics GP MVP Flexible Solutions, Inc. "Syed" <Syed@discussions.microsoft.com> wrote in message news:3B02ECEF-7436-4CF3-930E-AA4D2DFDF117@microsoft.com... ...

multiple flyers per page?
Hello. I need to make a custom template with publisher. It will be one 8 1/2 by 11 paper divided horizontally into three parts so that there are three fliers that can be printed. each flier needs to be double printed so I need to make it a double sided project like a postcard or brochure layout. I can figure out text and image stuff. But I don't know how to make a basic custom project that is divided into three panels horizontally (so 8 inches by 3.83 inches roughly) Also an additional customization would divide each 3.83 by 8 inch flyer into two parts so one 8 by 11 page would ...

PA Misc. Log Tables
Hi, How can I find the difference between Billed and Un-billed Miscelleneous Logs? Where Can I see Un-billed Misc. Logs and which tables. Hari I have a spreadsheet with the PA tables listed in it. Send an email message to charles.zarzour@intergraph.com and I will send you the spreadsheet. I do an excel spreadsheet for each Dictionary. Makes it easy to lookup tables. "Hari" wrote: > Hi, > How can I find the difference between Billed and Un-billed Miscelleneous > Logs? > Where Can I see Un-billed Misc. Logs and which tables. > > Hari > > Can I ...

Help, I cannot Save!
I created a document and locked the worksheet to protect the formulars before creating a template for the document. But now when I open th document and insert a new sheet using the template I created, th document will refuse to save. Once I click on save, office assistant will say "doc not saved". Wha could I have done wrong? PLease help. computerfinema -- computerfinema ----------------------------------------------------------------------- computerfineman's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=3716 View this thread: http://www.excelforum.c...

visual basic
Hi, I trying to retrieve values from a table to calculate the 14days average value of a stock closing price. However, i encounter some problem as stated beside the code as follows: Function DaysAvgs() 'Calculate the average value of a given value. Dim db As DAO.Database Dim rst As DAO.Recordset Dim varBookmark As Variant Dim numAve, numDaysAvg As Double Dim intA, intB, lngCount As Integer Set db = CurrentDb 'Open Table Set rst = db.OpenRecordset("SGX Individual Historical", dbOpenTable) rst.MoveFirst Do While Not rst.EOF intA = 1 intB = 0 varBookmark = rst.Bookmark n...

.pdf save as settings
Hi, In Office 2007 Pro is there a way to change the settings such as preventing content copying etc. when saving a file to pdf? I have been trialling Open Office, alongside Office 2007 Pro (full version not a trial), which allows access to these settings but I can't see a way to do it in MS Office. -- Chas MS Office doesn't do that. Chass wrote: > Hi, In Office 2007 Pro is there a way to change the settings such as > preventing content copying etc. when saving a file to pdf? I have been > trialling Open Office, alongside Office 2007 Pro (full version not...

Macro for Sharepoint List and another Table?? Same # records?
I am creating a database which we have a form made up of prepopulated data (from a sharepoint list) and also data input needed by a user (for example, comments, etc.). I have two tables: one sharepoint list that is linked to sharepoint website and another table that houses the additional user inputs [table 2]. I have linked the files based on the primary key. So, every record in my table 2 has a plus sign and it will expand and you will see the linked data from the sharepoint list. Is there a way that I can automatically create a record for every corresponding record ...

changing values of one field based on another
How can I best change the values of one field in a table based on values of another field of the same table. We have an existing table of thousands of entries and I would like to use the following logic to populate a new boolean field. If field1 = "Done" Then BooleanFieldCompleted = True I have some Excel VBA experience but limited Access. I dont want to do this manually! Any assistance appreciated. In general, you'd use an Update query. However, in this case I don't see why you'd need such a field. Why not just create a query with a computed field that returns True...

Phone Number Filtering
I am trying to sort special numbers in a long list of telephone numbers (7 digits). For example: a. Highlight yellow those numbers which have 3 consecutive digits (eg 2281555). b. Highlightt blue those numbers which have two double numbers (eg 4431122). c. Highlight green those numbers which are in a certain sequence (eg 2281234). I tried to use Left, Right and Mid formulas but the game becomes very complicated and hard to troubleshoot. Any better solution? The only effective way I know how to do this, is to use macros. Your samples a & b, are fairly simple to do. Sample c, could be d...

Fractions Number format
Is it possible to do a custom number format for cells such that fractions are displayed. I'm guessing not because there'd be a limit on what fractions you could display, but I would probably only be interested in showing a half as the little 1/2 (alt,0189 I think) rather than .5 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.478 / Virus Database: 275 - Release Date: 06/05/03 Lee There are a limited number of fractions that can be shown under Format>Cells>Fractions. Gord Dibben Excel MVP - XL97 SR2 & ...

Roman and Arabic numbers in SEQ
Running 2003 on XP. Got a doc that has SEQ numbering. The code is: ARTICLE{seq level0\h\r0}{seq level1\h\r0} etc. to level 7 and the last entry is {seq level0\r1\*ROMAN) This displays ARTICLE I The next level down is has this code: {seq level0\c\*ROMAN}.{seq level1\r1 \*arabic} This displays as : I.1, with numbers until article five displaying as V.1, V.2, etc. I want it to display as 1.1, 1.2, etc. I tried replacing the ROMAN with arabic, but it didn't change anything. I have spent hours trying to figure this out. Using reveal formating and styles, they are no styles...

Copying Data in a cell in one sheet to a cell in another sheet
I've run into a problem trying to copy data from a cell in one sheet to another. I have a spreadsheet called "rating" which contains a number of formula that calculates a final number. I also have a spreadsheet called "Final" that copies over the information from "Rating". In "Final", I'm trying to copy a number from "Rating" into a particular cell. I put in =Rating! G89, but it won't work. When I press enter, a window pops up "Update value:Rating". I press enter again and in the cell where I want the number ...

Invoice Numbers 10-27-07
We produce reports that are invoices.. The reports are really a group of compined reports if this matters... When we print the reports I would like to have printed consecutive invoice numbers. If possible I would like to have the number apprear as AS-00001, AS-00002 ect.. I am not really interested in storing the invoice numbers I just need them on the printed invoice as it is made of of groups of various data that is stored... Thank In Advance for you help. Bob If you just want a consequetive numbering on the report, all with an AS- prefix, see: Numbering Entries in a Report o...

Budget Wont Save
I have have Money 2002 for awhile and have never been able to save a budget and start a new one. I decided to start over with a new file, but once I get all my info back in there, it still won't save. MS has no info in the KB about this. Anyone else have this issue? ...

View original Excel after saving over it
In error, i hit save instead of save as. I'd like to view the original documents contents. is this at all possible. i use windows xp. excel 2003 Not very likely. Try a Google search action if you haven't already, but I think it's impossible. This underscores the importance of backups. -- Wigi http://www.wimgielis.be = Excel/VBA, soccer and music "houb" wrote: > In error, i hit save instead of save as. I'd like to view the original > documents contents. is this at all possible. i use windows xp. excel 2003 In article <C2A3F0E7-24E0-43A5-809A-ECA719...

Rounding Numbers #3
I have a list of values as below: 476.14 361.99 345.69 463.08 515.29 403.44 330.68 347.64 375.36 I would like to create a formula that rounds the values to the nearest 0.05 eg. Round 476.14 to 476.15, 361.99 to 362.00, 375.36 to 375.35 etc… Is there anyway that I can do this? Thanks, Jane. JaneC wrote: > I have a list of values as below: > 476.14 > 361.99 > 345.69 > 463.08 > 515.29 > 403.44 > 330.68 > 347.64 > 375.36 > I would like to create a formula that rounds the values > to the nearest 0.05 eg. Round 476.14 to 476.15, > 361.99 to 362.00, 375.36...

How to save Japanese characters in CSV format of Excel ?
Hi, I would like to know, how to save the Doubly-Byte characters.For example, Japanese in CSV of Excel.Here are the steps, I tried. 1. Open Excel 2. Copy pasted the Japanese charactesrs in a cell.It is displaying the characters correctly. 3. Save as CSV(Comma seperated file) It is saving as ??????. Thanks in advance for the info. ...

Saving e-mail & attachments when upgrading
I'm upgrading from NT4 to XP Home and the only data I need to keep are the emails & attachments. I have to format the hard drive to eliminate the partitions. This machine is on a network and I can save to the other machune. Look here for all the information you need on backup and restoration of Outlook data: http://www.slipstick.com/config/backup.htm -- Jocelyn Fiorello MVP - Outlook *** Replies sent to my e-mail address will probably not be answered -- please reply only to the newsgroup to preserve the message thread. *** "Mike" <mike@hosemart.com.au> wrote ...

item class table
I am creating SOP IM import. I need to fill the distribution fields with a rev account that is part of the item class. I would like to find a table that would hold the item class accounts. I looked in IV40400 and did not see any distribution accounts. What is the best table to pull these accounts. If the accounts have been defined on the Item Class, they will appear on the records in the IV40400 table. They're in the fields IVIVINDX, IVIVOFIX, etc - and they're just the keys to the actual account definitions in the GL00100 table. If a particular account type isn't defined ...

me too, problem with import... only 15 records
me too, problem with import... only 15 records.... also in one of my customers crm i need a fast answer.... I dont see a question to answer...? JUAN MARKETING wrote: > me too, problem with import... only 15 records.... also in one of my > customers crm > > i need a fast answer.... Hehe yeah, what is the question!? what are you trying to import? Sorry, I don't know the reason, bu each time i try to import x number of accounts or contacts, MSCRM only import 15 records... Promise, everything is ok... columns, format csv from excel, size, records.... I say that, becau...

Adding blank "separator" Rows in a Pivot Table
Does anyone know how to insert blank rows into a pivot table (say, between groupings, etc.)? There has to be a way, since some of the various table formats that come with Excel include blank rows. Double-click the field button that you want to format Click Layout Add a checkmark to Insert blank line after each item Click OK, twice Bucko wrote: > Does anyone know how to insert blank rows into a pivot table (say, > between groupings, etc.)? There has to be a way, since some of the > various table formats that come with Excel include blank rows. -- Debra Dalgleish Contextures http...

Auto calc YTD Numbers
Cells A1:L1 equal "Jan" thru "Dec". M1 equals "YTD". Cells A2:L2 equal numeric values. If you haven't guessed it already, I would like M2 to sum all the values A2:L2 for those months previous and including the current month (but not future months). What is the best way for going about this Here are 2 ways =SUM(OFFSET($A$2,,,,MATCH(TEXT(TODAY(),"mmm"),$A$1:$L$1,0))) or =SUM(OFFSET($A$2,,,,MONTH(TODAY()))) hopefully your computer's clock is accurate -- For everyone's benefit keep the discussion in the newsgroup. Regards, Peo Sjo...

Accessing another user's calendar OL2000/OL2003/Ex2000
Here's the situation: Running Exchange2000, v 6.0, sp4. Users are on XP/OL2003 or NT/OL2000. (we're in the process of upgrading all of the workstations to XP.) VIP user is on XP/OL2003. He can access his calendar just fine on his workstation. His secretary and other office admin type people are still on NT/OL2000. They have reviewer or editor rights to his calendar. They try to access his calendar by chosing File/Open/Other User's Folder... and put in his name and calendar. When they do this, the process hangs. In Task Manager, Outlook is "Running." End the Outloo...

How to use count for calls per hour
I am trying to create a pivot table and chart that will show me the # of calls per hour by day for a range of dates Aug 1 - Sept 19. My data looks like this where each line is the date and time of the call: How do I get a count of the # of the calls per hour by day? 8/1/08 12:48 AM 8/1/08 1:53 AM 8/1/08 2:36 AM 8/1/08 3:24 AM 8/1/08 3:37 AM 8/1/08 4:04 AM 8/1/08 4:44 AM 8/1/08 4:55 AM 8/1/08 4:58 AM 8/1/08 7:02 AM 8/1/08 7:28 AM 8/1/08 7:43 AM 8/1/08 7:47 AM 8/1/08 7:56 AM 8/1/08 7:58 AM 8/1/08 8:13 AM 8/1/08 8:33 AM 8/1/08 9:07 AM 8/1/08 10:28 AM 8/1/08 10:38 AM 8/1/08 10:44 AM 8/1/08 ...