Results 1 to 4 of 4
  1. #1
    bilalo is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    107

    counting records in parent table


    I have a parent table named order and a child table suborder where each order contains multiple suborders
    I created a report that shows all orders and suborders grouped by OrderID.
    I need to show the total number of orders., I used the function count(OrderID) in the report header but its showing me the total number of records in the report query which is count(SubOrderID) instead of count(OrderID).
    What am I doing wrong?

  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,898
    Try DCount() instead.

    =DCount("*", "Order", "same filter criteria as applied to the report")
    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
    bilalo is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    107
    Quote Originally Posted by June7 View Post
    Try DCount() instead.

    =DCount("*", "Order", "same filter criteria as applied to the report")
    The problem is that the orders are also grouped by date, so I need a dcount(orderno) for each month.
    I tried a dcount with filter on month(orderdate) but when the result is blank it is showing errors.
    I was thinking to use something similar to dcount(disctinct orderno) without applying any filter, in this case I do not have any repetition of suborders, is there something that works like this?
    Finally, I am wondering, is it true that ms access do not have a simple function like count(orderno) to count parent records directly from the report query?

  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,898
    Correct, Count() will count records of the query that is the report RecordSource. DCount() must reference table or query object and cannot modify with "DISTINCT".

    What do you mean by 'grouped by date'? A group section on year/month? You originally stated you wanted count of all orders in report header, that would not consider year/month. A DCount in group section could return count by year/month.

    =DCount("*", "Order", "Format([OrderDate], 'yyyymm')=" & Format([OrderDate], "yyyymm"))

    Why would result be blank and cause errors?

    If you want to 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.

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

Similar Threads

  1. Replies: 5
    Last Post: 05-04-2019, 07:04 AM
  2. Replies: 5
    Last Post: 05-21-2018, 03:53 PM
  3. Replies: 2
    Last Post: 08-24-2015, 02:56 PM
  4. Parent Child records in reporting
    By Darlene in forum Reports
    Replies: 1
    Last Post: 03-22-2014, 06:49 PM
  5. Relating parent and children records
    By Warrior in forum Forms
    Replies: 10
    Last Post: 07-24-2012, 04:57 PM

Tags for this Thread

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