Results 1 to 8 of 8
  1. #1
    JohnSmith is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2017
    Posts
    7

    Count All Records From SubReport Place Value On Main Report

    The main report shows a list of products with a list of cars that have been involved in an accident.



    Example Layout of Main report with integrated Sub report


    Total Cars: 1
    Accident1

    • Car1

    Accident2

    • CarA

    Accident3

    • Car5
    • CarD
    • Car3



    What I have done

    on the Sub report I placed a TextBox in the sub Report Header
    Sub Report Name: rptOwnersSubform
    TextBox Name: textCountOwners
    Control Source: =Count("*")

    on Main report I placed a TextBox in the Report Header
    Main Report Name: rptAccidents
    TextBox Name: text88
    Control Source: =[rptOwnersSubform].[Report]![textCountOwners]


    Issue
    I would like to count the number of cars that have been in an accident and place the number on the main report.
    The problem is the total number of cars is always 1. It seems it counts the number of cars per accident, which is not what I need.
    I want the total number of cars for the entire list, which should be 5.


    Test File.zip


    Thank you for any information you all can provide.
    Last edited by JohnSmith; 12-13-2020 at 04:52 PM.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,915
    You say customers are unique - there would not be same customer under multiple products?

    Suggest you provide db for analysis. Follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    JohnSmith is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2017
    Posts
    7
    I have edited my original post with the file.
    Thank You

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,915
    Maybe not optimized data structure. What you call a CarID is really ID of a person. Cars can be driven by different persons and persons can drive multiple cars. Cars and persons can be involved in multiple accidents.

    Should rptOwnersSubform be named rptOwnersSubreport ?

    Yes, the count is only the total records associated with the accident record that is displayed on main report. Calc in main report header is pulling from first accident and same calc in main report footer pulls from last accident. Total cars will have to be obtained with a subquery or DCount() expression.

    SELECT tblAccidents.*, (SELECT Count("*") FROM tblCars) AS TotCars FROM tblAccidents;

    Unfortunately that query fails as report RecordSource. So just bind report to table and expression in textbox: =DCount("*","tblCars")


    Both reports can just be bound to tables instead of queries because there is no calculating or filtering in queries.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Why not just use a dCount("*","YourSubReportRecordSource")?

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #6
    JohnSmith is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2017
    Posts
    7
    Thank you for the suggestions.

    I cannot bind it to the table, it must be bound from a queried result.


    I used
    Code:
    =DCount("*",[rptOwnersSubform].[Report]![LastName])
    in the Control Source of the main report named rptAccidents
    It's still showing #Error


    I have "cleaned up" the file so as to be a bit more normalized.
    Keep in mind this is not the real "DB" I use, I just created this one for this one problem that's kicking my a$$.
    I have attached it below.

    Better Test File.zip

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Please have a look at the attached file. If you need to limit the records in the subreport save its record source as a query then replace the table name in the dCount with the new query name.

    Cheers,
    Vlad
    Attached Files Attached Files
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  8. #8
    JohnSmith is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2017
    Posts
    7
    Thank you everyone.
    I have another issue, but I'll create another thread.
    This issue is solved.

    Thank You!!

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

Similar Threads

  1. Replies: 7
    Last Post: 04-16-2018, 07:43 PM
  2. Replies: 4
    Last Post: 08-07-2017, 08:09 AM
  3. Replies: 2
    Last Post: 02-04-2016, 08:13 AM
  4. Replies: 2
    Last Post: 03-31-2015, 03:32 AM
  5. Replies: 1
    Last Post: 04-15-2013, 10:02 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