locked
Conditional Visibility of a Line Control on a Report RRS feed

  • Question

  • I am trying to make lines visible in the groupheader, if there is detail for that group.

    If there is detail for this group, I want 2 lines to be visible in the group header, and one in the group footer.  If there is no detail for this group, I want the lines to be invisible. This needs to be re-evaluated for each group.

    I have tried to do this via the format event using the macro builder, but the visibility does not change, using any view, including print preview).

    This is pseudocode
    
    if isnull([detail.myField])
         setproperty line1.visibility = false
         setproperty line2.visibility = false
         setproperty line3.visibility = false
    else
         setproperty line1.visibility = true
         setproperty line2.visibility = true
         setproperty line3.visibility = true
    
    end if



    Tuesday, January 5, 2016 4:31 PM

Answers

  • Duh! Sorry. Of course each group will have at least 1. Try testing for null on one of the fields in the detail section.

    Private Sub GroupHeader0_Format(Cancel As Integer, FormatCount As Integer)
        Me.Line98.Visible = IsNull(Me.Order_ID) = False
        
    End Sub
    


    Bill Mosca
    www.thatlldoit.com
    http://tech.groups.yahoo.com/group/MS_Access_Professionals

    • Marked as answer by David_JunFeng Sunday, January 17, 2016 2:50 PM
    Tuesday, January 5, 2016 6:29 PM

All replies

  • In your group header, add a text box and name it txtCount and make it invisible. Set its controlSource to =Count([yourGroupIDname])

    Then check the value of txtCount in the group header format event. If it is greater than 0 set the line's visible to true. If it is not greater than 0 set it to false.


    Bill Mosca
    www.thatlldoit.com
    http://tech.groups.yahoo.com/group/MS_Access_Professionals

    Tuesday, January 5, 2016 5:24 PM
  • Did not work

    I am getting the lines for every group.

    I left the box visible and noted that Every Group has a count of 1, unless there is more than one detail.

    =Count([StepGroupBy])

    [StepBroupBy] is the field I am grouping on.

    Private Sub GroupHeader4_Format(Cancel As Integer, FormatCount As Integer)
        If Me.txtCount.Value > 0 Then
            Me.lneTop.Visible = True
            Me.lneBottom.Visible = True
        Else
            Me.lneTop.Visible = False
            Me.lneBottom.Visible = False
            Me.lneEnd.Visible = False
        End If
    End Sub

    Tuesday, January 5, 2016 5:47 PM
  • Duh! Sorry. Of course each group will have at least 1. Try testing for null on one of the fields in the detail section.

    Private Sub GroupHeader0_Format(Cancel As Integer, FormatCount As Integer)
        Me.Line98.Visible = IsNull(Me.Order_ID) = False
        
    End Sub
    


    Bill Mosca
    www.thatlldoit.com
    http://tech.groups.yahoo.com/group/MS_Access_Professionals

    • Marked as answer by David_JunFeng Sunday, January 17, 2016 2:50 PM
    Tuesday, January 5, 2016 6:29 PM
  • "Microsoft Access can't find the field 'TR_ID' referred to in your expression"

        If IsNull(Me.TR_ID) Then
            Me.lneTop.Visible = False
            Me.lneBottom.Visible = False
            Me.lneEnd.Visible = False
        Else
            Me.lneTop.Visible = True
            Me.lneBottom.Visible = True
            Me.lneEnd.Visible = True 
        End If

    Tuesday, January 5, 2016 6:36 PM
  • TR_ID is a field in the detail section and not in a sub report, right?

    Bill Mosca
    www.thatlldoit.com
    http://tech.groups.yahoo.com/group/MS_Access_Professionals

    Tuesday, January 5, 2016 7:21 PM
  • Correct
    Tuesday, January 5, 2016 7:23 PM
  • Sorry, Darcy. I tested it in a sample database and it worked for me. When you type Me.  in your code does Intellisense give you a list with TR_ID in it?

    Bill Mosca
    www.thatlldoit.com
    http://tech.groups.yahoo.com/group/MS_Access_Professionals

    Tuesday, January 5, 2016 8:08 PM
  • BTW - Thank you for your help

    Yes it intellisense does lead me to the field.  I am going to try to create a brand new report, minus all the things I messed with, and see if I can get it to work.

    Tuesday, January 5, 2016 8:18 PM
  • Okay, let us know how it goes. You might try my one-line style of coding. It's less typing. {smile}

    Bill Mosca
    www.thatlldoit.com
    http://tech.groups.yahoo.com/group/MS_Access_Professionals

    Tuesday, January 5, 2016 8:26 PM