Reputation: 1
I have e problem with my VBA/MSFORM code.
I have a userform with alot of checkboxes. I want the code to check when a checkbox is clicked. When it detect a click it should run a code. This part is working fine, but in the code the is executed upon a detection is updating a nother checkbox. When that checkbox is updated the code is exicuted again. How can i fix so the code is only exicuted when im clicking a checkbox and not updated by the code.
My class
Option Explicit
Private WithEvents chkBox As MSForms.CheckBox
Public Sub AssignClicks(ctrl As Control)
Set chkBox = ctrl
End Sub
Private Sub chkBox_Click()
MsgBox "Test"
AttachFiles.J_B_2.Value = True
End Sub
The InitializeCheckBoxHandlers function.
Option Explicit
Private colTickBoxes As Collection
Public Sub InitializeCheckBoxHandlers()
Dim ChkBoxes As cls_ChkBox
Dim ctrl As Control
Set colTickBoxes = New Collection
For Each ctrl In AttachFiles.Controls
If TypeName(ctrl) = "CheckBox" Then
If ctrl.Tag = "FD" Or ctrl.Tag = "2D" Or ctrl.Tag = "3D" Then
Set ChkBoxes = New cls_ChkBox
ChkBoxes.AssignClicks ctrl
colTickBoxes.Add ChkBoxes
End If
End If
Next ctrl
End Sub
And the InitializeCheckBoxHandlers
is called from the userform UserForm_Initialize()
function
As you can see i update checkbox J_B_2
and then the chkBox_Click
is exicuted again! How can i prevent this from happening?
I have tried removing the Handlers or applying tags to the clicked element without any luck
Upvotes: 0
Views: 32