For Each loop in report

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tuxalot
    New Member
    • Feb 2009
    • 200

    For Each loop in report

    Hi All,

    I have a report that I wish to have list boxes and their corresponding labels visible based on certain criteria. Is there a way to loop this code?

    Code:
    Private Sub Report_Activate()
    
    ' set all labels invisible
    
            Me.lblHead.Visible = False
            Me.lblFacial.Visible = False
            Me.lblEar.Visible = False
            Me.lblNeck.Visible = False
            Me.lblEye.Visible = False
            Me.lblShoulder.Visible = False
            Me.lblChest.Visible = False
            Me.lblElbow.Visible = False
            Me.lblArm.Visible = False
            Me.lblAbdomen.Visible = False
            Me.lblBack.Visible = False
            Me.lblWrist.Visible = False
            Me.lblHand.Visible = False
            Me.lblHip.Visible = False
            Me.lblThigh.Visible = False
            Me.lblKnee.Visible = False
            Me.lblAnkle.Visible = False
            Me.lblShin.Visible = False
            Me.lblFoot.Visible = False
    
    ' set all list boxes invisible
    
            Me.lstHead.Visible = False
            Me.lstFacial.Visible = False
            Me.lstEar.Visible = False
            Me.lstNeck.Visible = False
            Me.lstEye.Visible = False
            Me.lstShoulder.Visible = False
            Me.lstChest.Visible = False
            Me.lstElbow.Visible = False
            Me.lstArm.Visible = False
            Me.lstAbdomen.Visible = False
            Me.lstBack.Visible = False
            Me.lstWrist.Visible = False
            Me.lstHand.Visible = False
            Me.lstHip.Visible = False
            Me.lstThigh.Visible = False
            Me.lstKnee.Visible = False
            Me.lstAnkle.Visible = False
            Me.lstShin.Visible = False
            Me.lstFoot.Visible = False
    
    ' make labels and list boxes visible per query
    
    If [lstHead].ListCount > 0 Then
            Me.lblHead.Visible = True
            Me.lstHead.Visible = True
    End If
    
    If [lstFacial].ListCount > 0 Then
            Me.lblFacial.Visible = True
            Me.lstFacial.Visible = True
    End If
    
    If [lstEar].ListCount > 0 Then
            Me.lblEar.Visible = True
            Me.lstEar.Visible = True
    End If
    
    If [lstNeck].ListCount > 0 Then
            Me.lblNeck.Visible = True
            Me.lstNeck.Visible = True
    End If
    
    If [lstEye].ListCount > 0 Then
            Me.lblEye.Visible = True
            Me.lstEye.Visible = True
    End If
    
    If [lstShoulder].ListCount > 0 Then
            Me.lblShoulder.Visible = True
            Me.lstShoulder.Visible = True
    End If
    
    If [lstChest].ListCount > 0 Then
            Me.lblChest.Visible = True
            Me.lstChest.Visible = True
    End If
    
    If [lstElbow].ListCount > 0 Then
            Me.lblElbow.Visible = True
            Me.lstElbow.Visible = True
    End If
    
    ' and so on ......
    Thanks!
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by tuxalot
    Hi All,

    I have a report that I wish to have list boxes and their corresponding labels visible based on certain criteria. Is there a way to loop this code?

    Code:
    Private Sub Report_Activate()
    
    ' set all labels invisible
    
            Me.lblHead.Visible = False
            Me.lblFacial.Visible = False
            Me.lblEar.Visible = False
            Me.lblNeck.Visible = False
            Me.lblEye.Visible = False
            Me.lblShoulder.Visible = False
            Me.lblChest.Visible = False
            Me.lblElbow.Visible = False
            Me.lblArm.Visible = False
            Me.lblAbdomen.Visible = False
            Me.lblBack.Visible = False
            Me.lblWrist.Visible = False
            Me.lblHand.Visible = False
            Me.lblHip.Visible = False
            Me.lblThigh.Visible = False
            Me.lblKnee.Visible = False
            Me.lblAnkle.Visible = False
            Me.lblShin.Visible = False
            Me.lblFoot.Visible = False
    
    ' set all list boxes invisible
    
            Me.lstHead.Visible = False
            Me.lstFacial.Visible = False
            Me.lstEar.Visible = False
            Me.lstNeck.Visible = False
            Me.lstEye.Visible = False
            Me.lstShoulder.Visible = False
            Me.lstChest.Visible = False
            Me.lstElbow.Visible = False
            Me.lstArm.Visible = False
            Me.lstAbdomen.Visible = False
            Me.lstBack.Visible = False
            Me.lstWrist.Visible = False
            Me.lstHand.Visible = False
            Me.lstHip.Visible = False
            Me.lstThigh.Visible = False
            Me.lstKnee.Visible = False
            Me.lstAnkle.Visible = False
            Me.lstShin.Visible = False
            Me.lstFoot.Visible = False
    
    ' make labels and list boxes visible per query
    
    If [lstHead].ListCount > 0 Then
            Me.lblHead.Visible = True
            Me.lstHead.Visible = True
    End If
    
    If [lstFacial].ListCount > 0 Then
            Me.lblFacial.Visible = True
            Me.lstFacial.Visible = True
    End If
    
    If [lstEar].ListCount > 0 Then
            Me.lblEar.Visible = True
            Me.lstEar.Visible = True
    End If
    
    If [lstNeck].ListCount > 0 Then
            Me.lblNeck.Visible = True
            Me.lstNeck.Visible = True
    End If
    
    If [lstEye].ListCount > 0 Then
            Me.lblEye.Visible = True
            Me.lstEye.Visible = True
    End If
    
    If [lstShoulder].ListCount > 0 Then
            Me.lblShoulder.Visible = True
            Me.lstShoulder.Visible = True
    End If
    
    If [lstChest].ListCount > 0 Then
            Me.lblChest.Visible = True
            Me.lstChest.Visible = True
    End If
    
    If [lstElbow].ListCount > 0 Then
            Me.lblElbow.Visible = True
            Me.lstElbow.Visible = True
    End If
    
    ' and so on ......
    Thanks!
    When your Report becomes Active, the following code will make all Labels and List Boxes on the Report invisible:
    Code:
    Private Sub Report_Activate()
    Dim ctl As Control
    
    For Each ctl In Me.Controls
      With ctl
        Select Case .ControlType
          Case acListBox, acLabel
            ctl.Visible = False
          Case Else
        End Select
      End With
    Next
    End Sub

    Comment

    • tuxalot
      New Member
      • Feb 2009
      • 200

      #3
      Thanks! I appreciate your help.

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by tuxalot
        Thanks! I appreciate your help.
        Anytime, that is why we are all here.

        Comment

        Working...