
Originally Posted by
tulsaguy71
thanks AlphaFrog. Is there a way to make a loop or while statement? There are 16 checkboxes to get captions from just for the tasks. Im trying to avoid writing the code that many times!

This puts your FrameOQ Checkboxes in an array and traps their events in a class module.
Put this in the UserForm1 code module
'
Private OQCheckBoxes() As New OQCB_Events_class 'Place at the top of UserForm1 code module
'
Private Sub UserForm_Initialize()
Dim Counter As Long, c As Control
'Add the OQ Checkboxes to the array
For Each c In Me.FrameOQ.Controls
If TypeOf c Is MSForms.CheckBox Then
Counter = Counter + 1
ReDim Preserve OQCheckBoxes(1 To Counter)
Set OQCheckBoxes(Counter).OQCheckBox = c
End If
Next c
Set c = Nothing
End Sub
Insert a new class module and paste this code in it.
Name the Class Module OQCB_Events_class
' OQCB_Events_class module
' Event procedures for the FrameOQ CheckBoxes (OQCheckBoxes)
Public WithEvents OQCheckBox As MSForms.CheckBox
Private Sub OQCheckBox_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If OQCheckBox.Value = False Then
If MsgBox(Prompt:="Are you sure you want to make changes? ", _
Buttons:=vbYesNo, Title:="Confirm Action") = vbYes Then
OQCheckBox.Value = True
With frmOQDate
.lbOQtaskNum.Caption = OQCheckBox.Caption
.txtOQdate.Value = OQCheckBox.ControlTipText 'You could store a date in the .Tag property as well
.txtOQEmpName.Value = UserForm1.txtEditEmpName
.txtOQposition.Value = UserForm1.cboxEditPosition
.txtOQVeriforce.Value = UserForm1.txtEditVeriforce
.Show
End With
End If
End If
End Sub
Bookmarks