Hi,
Just as the title asks, wondering if its possible or if I have not set up the this code correctly.
Trying to loop through 34 check boxes and check if they equal true (checked) and then at the same time loop through my 34 text boxes with some dates and additions.
Was hoping this would work and save me a lot of typing or copying and pasting by just creating this once in a sub CheckBoxes and calling to it from the check boxes click events.
Here is what I thought would work
Sub Checkboxes()
'Check box to put a date and time stamps in DateSprayed, ReEntry, and PHI text boxes on userform
Dim i As Integer
Dim x As Integer
With Checklist
For i = 1 To 34
If Me.Controls("chk" & i) = True Then
With Checklist
For x = 1 To 34
Me.Controls("txtDateSprayed" & x).Value = Now()
Me.Controls("txtReEntry" & x).Value = DateAdd("H", txtMaxReEntry, Me.Controls("txtDateSprayed" & x).Value)
Me.Controls("txtPHI" & x).Value = DateAdd("H", txtMaxPHI, Me.Controls("txtDateSprayed" & x).Value)
Next x
End With
Else
With Checklist
For x = 1 To 34
Me.Controls("txtDateSprayed" & x).Value = ""
Me.Controls("txtReEntry" & x).Value = ""
Me.Controls("txtPHI" & x).Value = ""
'Format to dates and times
Me.Controls("txtDateSprayed" & x).Value = Format(Me.Controls("txtDateSprayed" & x).Value, "mmm-dd-yy - HH:MM")
Me.Controls("txtReEntry" & x).Value = Format(Me.Controls("txtReEntry" & x).Value, "mmm-dd-yy - HH:MM")
Me.Controls("txtPHI" & x).Value = Format(Me.Controls("txtPHI" & x).Value, "mmm-dd-yy - HH:MM")
Next x
End With
End If
Next i
End With
End Sub
Thanks to anyone who may shed some light on this.
Bookmarks