Hi.
I'm trying to build a dynamic form and I'm facing some troubles assigning events to the created elements.
Basically once the user clicks a checkbox previowsly created the program creates a lot of fields for information input and the checkbox to enable the next line of information in the form (if the checkbox is clicked the program will repeat the process of creating the fields).
Everytime I create a new checkbox I assign an event handler to it, just as follows:
MODULE SUB:
Dim cls As csBoletaDeCompra, DynamicCheckBox As Collection
'Cria o checkBox da linha seguinte
Set DynamicCheckBox = New Collection
Set cls = New csBoletaDeCompra
Set cls.DynamicCheckBox = ufmBoletaDeCompra.frmProdutos.Add("Forms.CheckBox.1", "chk_" & n + 1, True)
With cls.DynamicCheckBox
.Top = inicialTop + n * gapLines
.left = leftChk
.Value = False
.Tag = n + 1
.SetFocus
End With
DynamicCheckBox.Add cls
CLASS MODULE:
Public WithEvents DynamicCheckBox As MSForms.CheckBox
Private Sub DynamicCheckBox_Change()
If DynamicCheckBox.Value = True Then
Call boletaCompra_CriaLinha(DynamicCheckBox.Tag)
ElseIf DynamicCheckBox.Value = False Then
Call boletaCompra_EliminaLinhas(DynamicCheckBox.Tag)
End If
End Sub
The problem is: When I create a checkbox, the previows checkbox stops responding to the _Change event and the class sub is not called anymore.
Is there something missing in my code?
Thanks a lot.
Bookmarks