Results 1 to 8 of 8
  1. #1
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591

    Counting Detail Records by Group

    I'm brushing up on my report design chops and I'm stubbing my toe on something simple. I was a count of how many records are in each detail section and I can't remenber how to do it. If the record count = 0 then I want to run some code.

    Hope you can help,

    Thanks

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    What do you mean by 'each' detail section? A report has only one Detail section. Do you mean group section?

    Perhaps you need to apply a filter to report so do not have groups without records.

    Provide more information on what you are trying to accomplish so that we can better advise.
    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
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    OK, I have 3 controls in a group header, two labels and a line that I want to hide if there is no detail.

    BTW I couldn't find the HasData event and Access Help came up empty.

  4. #4
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    I found the HasData of the Report, but I'm still not sure how or where to use it to accomplish the above task.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I removed my comments about HasData after re-reading your post.

    You might try the OnFormat event of the group header. I have done this in Detail section OnFormat event, never tried for group.

    If IsNull(Me!somefieldname) Then
    Me.controlname.Visible = False
    End If

    There will be blank space on report occupied by the invisible control. Can't reduce the blank area because controls are still there.
    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.

  6. #6
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    I tried tried this code in OnFormat of the header. txtCount uses =Count([Product_ID]) as a Control Source. Product_ID is a text box in the detail section.

    Code:
            With Me
        If .txtCount = 0 Then
               .Line_Grandchild.Visible = False
               .lblGrandchild.Visible = False
               .lblUPC.Visible = False
            End If
        End With
    I can't get the code to run. I put a break in to catch and got nothing and also a msgbox. I tried On Paint. The code ran, but you can't change those properties in the OnPaint event.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I think the code will execute only when report is in PrintPreview or sent directly to print. All I know is that OnFormat works for Detail section. Never used OnPaint or OnPrint.
    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.

  8. #8
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    Of course I knew that or should have. The report is starting to come around. These growing pains are making me old(er).

    Thank you.

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

Similar Threads

  1. Combine master detail records in one query
    By mariost in forum Queries
    Replies: 4
    Last Post: 05-14-2011, 11:25 AM
  2. Replies: 3
    Last Post: 04-18-2011, 06:52 PM
  3. additional detail records to be inserted
    By Mclaren in forum Reports
    Replies: 1
    Last Post: 03-16-2011, 02:10 AM
  4. Counting Records
    By WhiteNite1971 in forum Access
    Replies: 1
    Last Post: 01-22-2011, 06:36 AM
  5. columns for group detail but not group header?
    By Coolpapabell in forum Reports
    Replies: 0
    Last Post: 08-21-2009, 08:53 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