Results 1 to 7 of 7
  1. #1
    hfreedman1957 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2017
    Posts
    35

    store detail table record count in header table

    Hi,
    I have a main table called project, one record per project. I have a detailed table which hold many records per project. I want to count the records in the detail table for each project and store the count in the project table. There will be a couple extra criteria for selecting records from the detail file aside from project ID. There are at most 30 projects and hundreds of detail records per project. This is not a large database.
    Should I do this entirely in VBA, looping through the details for each project record, or can/should this be accomplished with a combination of VBA and a query? Please provide an approach. The more detailed the more beneficial. Thanks so much!
    Howard

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Do not store calculated values on tables. Create a standard query which is used each time you need the value.

    Create a select query on the second table, select project id twice. Click on the Totals icon at the top, a new line will be added below. Select Group By for the first field and Count for the second. Add the additional criteria as needed.

  3. #3
    hfreedman1957 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2017
    Posts
    35
    Actually, my plan already was to run the query/program each time I need the values, as you suggested. The reason I wanted to update the project file with the count values is that I run a customized report (VBA) using the project file only, and it would be much easier for me of those count values were on the project records as well.
    With that, I'll try your solution above and see if I can incorporate that query into my customized report. Thanks!

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Not sure what you mean by "customized report (VBA)", but instead of using only the project table join in the count query into the query statement.

  5. #5
    hfreedman1957 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2017
    Posts
    35
    For this particular report, I currently don't use the detailed table. The report starts as VBA code which is triggered from an event that runs an Access report which has a project table query as record source, and generates a separate report for each project record, converts it into PDF format, attaches it to an email to be sent to the Project Manager of that project (record). This loops through and repeats for each project record. I don't touch the detail table. Inside the Access report are many calculations and I now have a requirement to incorporate those counts into these calculations. It would just be much easier if the counts were present on each project record by running an update query and/or VBA code to update the project records with the counts prior to the running of this report.

  6. #6
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    which has a project table query as record source
    Add the counts query to the record source.

    Either that or before you run the report, run a query to make a table with the counts and another query to update from that temp table. Or else loop thru the records in VBA and update them.

  7. #7
    hfreedman1957 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2017
    Posts
    35
    ok, I'll give that a shot. Thanks so much!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 01-12-2017, 02:30 AM
  2. Replies: 4
    Last Post: 11-16-2015, 08:15 AM
  3. Replies: 4
    Last Post: 09-21-2014, 04:08 PM
  4. Select Just First Header/Detail Row
    By EddieN1 in forum Queries
    Replies: 5
    Last Post: 02-20-2014, 11:19 PM
  5. Record count in Access table using VBA
    By shubhamgandhi in forum Programming
    Replies: 2
    Last Post: 07-20-2011, 11:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums