Variable dans UserForm avec If

thehaker42

XLDnaute Nouveau
Bonjour le forum
aujourd'hui c'est les variables qui me coincent
avec le petit bout de programme, issue de mon gros fichier excel, bug: "Erreur de compilation: Membre de méthode ou de données introuvable"

Or je déclare ma variable k, ...
est ce une histoire de public/private?
est ce une histoire de conception?
est ce une faute de frappe?

Merci

UserForm1:

Code:
Private Sub CommandButton2_Click()
    
    Dim k As String

        If UserForm1.ComboBox1.Value <> "1" Then
        Me.k = UserForm1.ComboBox1.Value & ".doc"

        If UserForm1.ComboBox1.Value = "1" And OptionButton1.Value = True Then
        Me.k = "1A" & ".doc"

        If UserForm1.ComboBox1.Value = "1" And OptionButton2.Value = True Then
        Me.k = "1B" & ".doc"

        If UserForm1.ComboBox1.Value = "1" And OptionButton3.Value = True Then
        Me.k = "1C" & ".doc"

        End If
        End If
        End If
        End If

    Me.Label1.Caption = k

UserForm1.Hide
UserForm2.Show

End Sub

UserForm2:

Code:
Private Sub UserForm_Initialize()

  Label1.Value = UserForm1.Label1.Value

End Sub

Regarde la pièce jointe userform.xls
 

Pièces jointes

  • userform.xls
    39 KB · Affichages: 138
  • userform.xls
    39 KB · Affichages: 131

phlaurent55

Nous a quittés en 2020
Repose en paix
Re : Variable dans UserForm avec If

Bonjour thehaker,

essaie ceci:
Code:
Private Sub CommandButton2_Click()
Dim k As String
If UserForm1.ComboBox1.Value <> "1" Then
Me.Label1.Caption = UserForm1.ComboBox1.Value & ".doc"
If UserForm1.ComboBox1.Value = "1" And OptionButton1.Value = True Then
Me.Label1.Caption = "1A" & ".doc"
If UserForm1.ComboBox1.Value = "1" And OptionButton2.Value = True Then
Me.Label1.Caption = "1B" & ".doc"
If UserForm1.ComboBox1.Value = "1" And OptionButton3.Value = True Then
Me.Label1.Caption = "1C" & ".doc"
End If
et
Code:
Private Sub UserForm_Initialize()
UserForm2.Label1.Caption = UserForm1.Label1.Caption
End Sub

à+
Philippe
 

thehaker42

XLDnaute Nouveau
Re : Variable dans UserForm avec If

Merci de m'avoir montré la voie :)
je l'ai encore modifié poru qu'il soit opérationnel
Merci phlaurent55 ;)

Code:
Private Sub CommandButton2_Click()


        If UserForm1.ComboBox1.Value <> "1" Then
        Me.Label1.Caption = UserForm1.ComboBox1.Value & ".doc"

        ElseIf ((UserForm1.ComboBox1.Value = "1") And (OptionButton1.Value = True)) Then
        Me.Label1.Caption = "1A" & ".doc"

        ElseIf ((UserForm1.ComboBox1.Value = "1") And (OptionButton2.Value = True)) Then
        Me.Label1.Caption = "1B" & ".doc"

        Else
        '((UserForm1.ComboBox1.Value = "1") And (OptionButton3.Value = True)) Then
        Me.Label1.Caption = "1C" & ".doc"

        End If

UserForm1.Hide
UserForm2.Show

End Sub
 

Discussions similaires

Statistiques des forums

Discussions
311 734
Messages
2 082 020
Membres
101 872
dernier inscrit
Colin T