Checkbox active une text box dans formulaire de saisie

Bonjour

Je suis en train de créer un formulaire de saisie sur VBA et je cherche à activer une textbox si une checkbox est cocher ou non

Cependant avec le code suivant je n'y arrive pas. Pouvez me donnez votre avis ?

Merci

Private Sub Activer()

If cbox1 = True Then

txt1.Enabled = True

Else

txt1.Enabled = False

End Sub

Salut

Il y a trois façons de faire ca

'1
Private Sub CheckBox1_Click()
    If CheckBox1.Value = False Then
    TextBox1.Enabled = False
    Else
    TextBox1.Enabled = True
    End If
End Sub

'2
Private Sub CheckBox1_Click()
    If CheckBox1.Value = False Then TextBox1.Enabled = False Else TextBox1.Enabled = True
End Sub

'3
Private Sub CheckBox1_Click()
    TextBox1.Enabled = IIf(CheckBox1.Value = False, False, True)
End Sub

bonjour

1 Module de classe

Option Explicit        ' Pour obliger à déclarer les variables
Public WithEvents ChckB As MSForms.CheckBox, F As Byte
Private Sub ChckB_Click()
    F = Right(ChckB.Name, Len(ChckB.Name) - 8)
    With Usf_Recherche_Des_Contacts
        .Controls("TextBox" & F).Visible = ChckB
    End With
End Sub

2 Dans l'Userform

Option Explicit        ' Pour obliger à déclarer les variables

Dim F As Byte        ' Déclare les variables C et F (Incrément)
Dim ChckB(68) As New ClasseChckB        ' Déclare la variable ChckB
Dim Wsz As Worksheet        ' Déclare les variables (Onglet)

Private Sub UserForm_Initialize()        ' ........................................................à l'initialisation de l'UserForm
    For F = 1 To 68: Me("TextBox" & F).Visible = False: Set ChckB(F).ChckB = Controls("CheckBox" & F): Next F
End Sub
Private Sub CmdB_Exporter_Click()        '.Bouton Exporter
    Set Wsz = Sheets("Feuille Temporaire")
    Application.ScreenUpdating = False
    For t = 1 To 68
        If Me.Controls("Checkbox" & t).Value = True Then
            GoTo LaSuite
        Else
            MsgBox "Vous n'avez rien coché !?", 48, "Attention"
            Exit Sub
        End If
    Next t
LaSuite:
    Wsz.Cells.ClearContents
    For M = 1 To 68
        If Me.Controls("CheckBox" & M).Value = True Then
            Wsz.Cells(1, M).Value = Me.Controls("CheckBox" & M).Caption
            Wsz.Cells(2, M).Value = Me.Controls("TextBox" & M).Value
        End If
End Sub
Private Sub Lbl_Cocher_Click(): For M = 1 To 68: Me.Controls("CheckBox" & M).Value = True: Next M: End Sub
Private Sub Lbl_Decocher_Click(): For M = 1 To 68: Me.Controls("CheckBox" & M).Value = False: Next M: End Sub
Sub Initialise_ListBox1()
    For M = 1 To 68: Me.Controls("CheckBox" & M).Value = True: Next M
    For t = 1 To 68
        Me.Controls("TextBox" & t) = ListBox1.List(ListBox1.ListIndex, t - 1)
    Next t
    ' Activer/désactiver CheckBox si TextBox vide
    For t = 1 To 68
        If Me.Controls("TextBox" & t) = "" Then Me.Controls("CheckBox" & t).Value = False
    Next t
End Sub
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)        ' .....................Au double-clic dans la ListBox1
    Initialise_ListBox1
    UserForm_Layout ' pour les formats
End Sub

Cordialement

Rechercher des sujets similaires à "checkbox active text box formulaire saisie"