Loop through controls on main form with several sub forms

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • p4willi
    New Member
    • Jun 2010
    • 22

    #1

    Loop through controls on main form with several sub forms

    Hi not sure if my earlier post was sent due to idle time so here I go again....

    On my main form when I press the save button it has to loop through several sub forms within tabs and determine if the optiongroup within them are set to a certain value.

    How would I do a single loop structure to accomplish this from my main form calle frmMain. Presently I am doing it separately for each form as below:
    Code:
       For Each ctl In Form_frmHeader.Controls
            Select Case ctl.ControlType
            Case acOptionGroup
                If ctl.Value = 2 Then
                    Correct = True
                    Exit For
                End If
            End Select
        Next ctl
    
       For Each ctl In Form_frmLines.Controls
            Select Case ctl.ControlType
            Case acOptionGroup
                If ctl.Value = 2 Then
                    Correct = True
                    Exit For
                End If
            End Select
        Next ctl
       
       For Each ctl In Form_frmSummary.Controls
            Select Case ctl.ControlType
            Case acOptionGroup
                If ctl.Value = 2 Then
                    Correct = True
                    Exit For
                End If
            End Select
        Next ctl
       For Each ctl In Form_frmDocHist.Controls
            Select Case ctl.ControlType
            Case acOptionGroup
                If ctl.Value = 2 Then
                    Correct = True
                    Exit For
                End If
            End Select
        Next ctl
       For Each ctl In Form_frmNotes.Controls
            Select Case ctl.ControlType
            Case acOptionGroup
                If ctl.Value = 2 Then
                    Correct = True
                    Exit For
                End If
            End Select
        Next ctl
    thanks
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    Normally You can run through the active forms with this=
    (see attachment)

    Code:
    Private Sub Command1_Click()
    Dim ACTIVE As Integer
    Dim i As Integer
       For i = 0 To Forms.Count - 1
          If Forms(i).Check1 Then ACTIVE = ACTIVE + 1  
       Next
       Text1.Text = ACTIVE
    End Sub
    Attached Files

    Comment

    • p4willi
      New Member
      • Jun 2010
      • 22

      #3
      As always - thanks ggeu. Your tip has helped me.

      Comment

      Working...