1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| Private Sub CommandButton1_Click()
Dim ctl As Control
Dim sCheckBox As String
Dim sTextBox As String
Dim sNum As String
Dim sTxtName As String
sCheckBox = "CheckBox" ' Les noms des Checkbox doivent commencer par ce string suivi de chiffres
sTextBox = "TextBox" ' Les noms des Textbox doivent commencer par ce string suivi de chiffres correspondants
' à ceux du checkbox associé
For Each ctl In Me.Controls
If Left(ctl.Name, Len(sCheckBox)) = sCheckBox Then
If ctl.Value = -1 Or IsNull(ctl.Value) Then
sNum = Right(ctl.Name, Len(ctl.Name) - Len(sCheckBox))
sTxtName = sTextBox & sNum
If Not Me.Controls(sTxtName).Value = vbNullString Then
ctl.Caption = Me.Controls(sTxtName).Value
End If
End If
End If
Next ctl
End Sub |