Hi
I am trying to write a generic procedure to be called before and after any and all processes to do one of the following two tasks based on an input parameter:
1. (When called in the pre-process mode): Save the Enabled properties of all controls on the form in two arrays (one for the name of the control, and another for the value of the Enabled property), and then Set the Enabled properties of all these controls to False (and therefore disabling all of them)
2. (When called in the post-process mode): Restore the Enabled properties of all the controls on the form to their initial values (as saved above).

This procedure is in a bas module, so that all vbp projects can attach that bas module to themselves and use this procedure.
The way my generic procedure identifies all the controls on the form is to use the following structure:
Code:
For Each Ctrl In TheForm.Controls
   ...
Next
My generic procedure works perfectly when all the controls on the form are singular not arrays of controls (control arrays).
My procedure does not properly distinguish each item within a control array separately.
How can I fix my procedure to loop through not just each control and each control array (as it currently does), but to also loop through each element or each item of the control array (each individual control that is part of a control array)?
Here is my procedure as I have currently coded it:
Code:
Public Sub ToggleControlsEnabled( _
                                    ByRef TheForm As Form, _
                                    ByRef ToggleCtrlsEnabledDisabled As ToggleCtrlsEnabledDisabledType, _
                                    ByRef BfrStateCtrlName() As String, _
                                    ByRef BfrStateCtrlEnabledSetting() As Boolean _
                                )
   
   Dim Ctrl                                 As Control
   Dim CtrlsEnabledSetting                  As Boolean
   Dim i                                    As Long
   Dim L                                    As Long

   'Init
   If ToggleCtrlsEnabledDisabled = tcedToggleDisablePreProcess Then
      CtrlsEnabledSetting = False                                           ' Preparations for pre-process toggling
      
      Erase BfrStateCtrlName()
      Erase BfrStateCtrlEnabledSetting()
   Else
      CtrlsEnabledSetting = True                                            ' Preparations for post-process toggling
   End If
   
   'Main: Pre-process toggling: Toggling the controls disabled
   If ToggleCtrlsEnabledDisabled = tcedToggleDisablePreProcess Then
      For Each Ctrl In TheForm.Controls
         If (TypeOf Ctrl Is CommandButton) Or (TypeOf Ctrl Is TextBox) Or (TypeOf Ctrl Is Label) Or (TypeOf Ctrl Is CheckBox) Or (TypeOf Ctrl Is OptionButton) Or (TypeOf Ctrl Is SSTab) Or (TypeOf Ctrl Is Frame) Then
            L = LengthOfArray(BfrStateCtrlName())
            
            ReDim Preserve BfrStateCtrlName(L) As String
            ReDim Preserve BfrStateCtrlEnabledSetting(L) As Boolean
            
            BfrStateCtrlName(L) = Ctrl.Name
            BfrStateCtrlEnabledSetting(L) = Ctrl.Enabled
         End If
      Next
      
      For Each Ctrl In TheForm.Controls
         If (TypeOf Ctrl Is CommandButton) Or (TypeOf Ctrl Is TextBox) Or (TypeOf Ctrl Is Label) Or (TypeOf Ctrl Is CheckBox) Or (TypeOf Ctrl Is OptionButton) Or (TypeOf Ctrl Is SSTab) Or (TypeOf Ctrl Is Frame) Then
            Ctrl.Enabled = CtrlsEnabledSetting
         End If
      Next
      
   End If
   
   'Main: Post-process toggling: Toggling the controls ensabled
   If ToggleCtrlsEnabledDisabled = tcedToggleEnablePostProcess Then
      L = LengthOfArray(BfrStateCtrlName())
      
      For Each Ctrl In TheForm.Controls
         If (TypeOf Ctrl Is CommandButton) Or (TypeOf Ctrl Is TextBox) Or (TypeOf Ctrl Is Label) Or (TypeOf Ctrl Is CheckBox) Or (TypeOf Ctrl Is OptionButton) Or (TypeOf Ctrl Is SSTab) Or (TypeOf Ctrl Is Frame) Then
            For i = 0 To L - 1
               If UCase(Ctrl.Name) = UCase(BfrStateCtrlName(i)) Then
                  Ctrl.Enabled = BfrStateCtrlEnabledSetting(i)
                  Exit For
               End If
            Next i
         End If
         
      Next
   End If
   
   'Final
   DoEvents
   
End Sub
Please advise.
Thanks