Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2005
    Posts
    333

    Unanswered: Scan report and hide textboxes

    I have a report that I want to hide/show textboxes based on certain criteria. I have this working by hardcoding the textbox names like:
    Code:
     
    Reports!textbox1.visible=true
    Although this works it's not very dynamic, i.e. I have to manually add/remove lines of code every time a box is added/removed. I want to use the textbox tag to identify the criteria and then use a "for each" loop to iterate through each textbox object in the Detail section of my report.

    Something like the pseudo-code below. I just don't know the type of collection to use to limit it to textboxes in the detail section.
    Code:
     
    For each obj in someCollection
      if obj.tag = "showme" then
        obj.visible = true
      else
        obj.visible = false
      end if
    next obj

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    I use this in forms; I assume it will also work in a report:

    Code:
      Dim ctl As Control
    
      For Each ctl In Me.Controls
        'your code here, using "ctl" instead of "obj"
      Next ctl
    Paul

  3. #3
    Join Date
    Feb 2005
    Posts
    333
    Thanks Paul

    This worked (kind of). The problem is that is hides the header, footer, etc. Does any one know how to limit the control collection to only controls in the detail section of the report?
    Code:
     
     
    Private Sub Report_NoData(Cancel As Integer)
        Dim ctl As Control
            
        For Each ctl In Controls
            If ctl.Tag = "showonempty" Then
                ctl.Visible = True
            Else
                ctl.Visible = False
            End If
        Next ctl
       
    End Sub

  4. #4
    Join Date
    Feb 2005
    Posts
    333
    I took the easy way out. I used the controtype property to keep any lines, pictures, etc and then added tag values to any label or textbox that I want to show all the time.


    Code:
     
    Private Sub Report_NoData(Cancel As Integer)
        Dim ctl As Control
            
        For Each ctl In Controls
            If ctl.ControlType = acLabel Or _
               ctl.ControlType = acTextBox Then
                If ctl.Tag = "show" Then
                    ctl.Visible = True
                ElseIf ctl.Tag = "showonempty" Then
                    ctl.Visible = True
                Else
                    ctl.Visible = False
                End If
            End If
        Next ctl
    End Sub

  5. #5
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Well, you can test for types of controls with ctl.ControlType, like testing for acTextBox. That should stop it from hiding sections.
    Paul

  6. #6
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Oops; too slow typing. Glad you have it working.
    Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •