none
Hide GroupHeader based on the number of records in the detail RRS feed

  • Question

  • I have a form with groupheader0.

    I have a txtcount is a text box with count(*)  on groupheader0.  This is working fine.

    I would like to hide any groupheader (and associated details) where count=1

    I have tried putting code in the groupheader0 on format event

    If me.txtcount = 1 then

      me.groupheader0.visible = False

    End If

    This does not work.

    Any suggestions?


    MS - Teach me to fish

    Wednesday, October 12, 2016 5:16 PM

Answers

  • Hi,

    If "nothing" happened, then it might mean the event didn't fire. Try viewing the report in Print Preview rather than Report View. Or, just print it out...

    Wednesday, October 12, 2016 5:33 PM
  • If "nothing" happened, then it might mean the event didn't fire. Try viewing the report in Print Preview rather than Report View. Or, just print it out...

    I think thDBguy is right.  The Format events don't fire in Report View.  I find that I can show/hide the group header in Print Preview, using code like this:

        If Me.txtCount = 1 Then
            Me.GroupHeader0.Visible = False
        Else
            Me.GroupHeader0.Visible = True
        End If
    

    Which incidentally is equivalent to this:

        Me.GroupHeader0.Visible = Not (Me.txtCount = 1)
    

    Or you can cancel the Format event:

    Private Sub GroupHeader0_Format(Cancel As Integer, FormatCount As Integer)
        
        If Me.txtCount = 1 Then
            Cancel = True
        End If
    
    End Sub
    
    All of those work for me, so long as I'm not opening the report in Report View.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Wednesday, October 12, 2016 9:21 PM

All replies

  • Hi,

    Just want to make sure we're on the same page, you said you have a "form" with a header, and yet you also said you tried to use the "format" event, which I am not sure forms have. Are you actually referring to using a "report?"

    Also, what does "does not work" mean? Did you get an error? Nothing happened? Something unexpected happened?

    Thanks!

    • Edited by .theDBguy Wednesday, October 12, 2016 5:22 PM
    Wednesday, October 12, 2016 5:21 PM
  • My bad. 

    It is a report.

    Didn't work means nothing happened at all.

    My bad again.  I didn't put any error handling in.  I did add a msgbox in the if statement "got here", which also did not happen.


    MS - Teach me to fish

    Wednesday, October 12, 2016 5:30 PM
  • nothing =

    the report did not change, no msg box displayed.


    MS - Teach me to fish

    Wednesday, October 12, 2016 5:31 PM
  • Hi,

    If "nothing" happened, then it might mean the event didn't fire. Try viewing the report in Print Preview rather than Report View. Or, just print it out...

    Wednesday, October 12, 2016 5:33 PM
  • If "nothing" happened, then it might mean the event didn't fire. Try viewing the report in Print Preview rather than Report View. Or, just print it out...

    I think thDBguy is right.  The Format events don't fire in Report View.  I find that I can show/hide the group header in Print Preview, using code like this:

        If Me.txtCount = 1 Then
            Me.GroupHeader0.Visible = False
        Else
            Me.GroupHeader0.Visible = True
        End If
    

    Which incidentally is equivalent to this:

        Me.GroupHeader0.Visible = Not (Me.txtCount = 1)
    

    Or you can cancel the Format event:

    Private Sub GroupHeader0_Format(Cancel As Integer, FormatCount As Integer)
        
        If Me.txtCount = 1 Then
            Cancel = True
        End If
    
    End Sub
    
    All of those work for me, so long as I'm not opening the report in Report View.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Wednesday, October 12, 2016 9:21 PM