Hi all,
My UserForm.Initialize() call SetControlEvents. This function purpose is to find all my ComboBox and TextBox controls and attach to them, a class module events. I use recursive because Frame and MultiPage are container. My Initial call to this function is :
At runtime, I obtain this error : "Compile error: Argument not optional"
and the ".Controls" is highlighted
When I try with this argument :
I obtain a "Runtime error 13:Type mismatch" and the line where VBA stops is
Here is my complete function code :
Thank you for any suggestion/help.
Laurent
My UserForm.Initialize() call SetControlEvents. This function purpose is to find all my ComboBox and TextBox controls and attach to them, a class module events. I use recursive because Frame and MultiPage are container. My Initial call to this function is :
Code:
SetControlEvents(Me.Controls)
and the ".Controls" is highlighted
When I try with this argument :
Code:
SetControlEvents(Me)
Code:
SetControlEvents (Ctrl.Pages(I))
Code:
Private Sub SetControlEvents(AControls As MSForms.Controls)
Dim Ctrl As MSForms.Control
Dim I As Integer
Dim CtrlEvents As clsControlEvents ' Définition de notre Class Module dans l'unité "clsControlEvents"
For Each Ctrl In AControls
Select Case TypeName(Ctrl)
Case "Frame"
SetControlEvents (Ctrl)
Case "MultiPage"
For I = 0 To Ctrl.Pages.Count - 1
SetControlEvents (Ctrl.Pages(I))
Next I
Case "ComboBox"
' Reprendre la boucle du UserForm_Initialize()
If Left(Ctrl.Name, Len(CBXSECTION) - 1) = CBXSECTION Then
Ctrl.Tag = ""
If Val(Right(Ctrl.Name, Len(Ctrl.Name) - Len(CBXSECTION))) > 1 Then
Ctrl.Enabled = False
End If
Set CtrlEvents = New clsControlEvents ' Les variables ComboBox et Form sont déclarées
Set CtrlEvents.ComboBox = Ctrl ' dans notre Class Module "clsControlEvents"
Set CtrlEvents.Form = Me ' La variable Collection cbxSections est déclarée
cbxSections.Add CtrlEvents ' au niveau de cette UserForm (tout en haut de ce module)
End If
Case "TextBox"
If Left(Ctrl.Name, 3) = "tbx" Then
' to become...
End If
End Select
Next Ctrl
End Sub
Laurent