Comment interrompre un commandbutton

Résolu
mythiac Messages postés 72 Date d'inscription mardi 23 septembre 2008 Statut Membre Dernière intervention 23 février 2009 - 24 déc. 2008 à 15:03
mythiac Messages postés 72 Date d'inscription mardi 23 septembre 2008 Statut Membre Dernière intervention 23 février 2009 - 24 déc. 2008 à 16:12
bonjour,

j'aimerais savoir comment interrompre un commandbutton

en gros, obliger à remplir tous les champs mais comme ceci:

Private Sub CommandButton2_Click()
If UserForm14.TextBox1 "" Or UserForm14.ComboBox1 "" Or UserForm14.TextBox2 = "" Or UserForm14.TextBox3 = "" Or UserForm14.TextBox4 = "" Or UserForm14.TextBox5 = "" Or UserForm14.TextBox6 = "" Then
        MsgBox "Remplir tous les champs"

   '     revenir sur le textbox1

       
End If

..............suite des instructions

End Sub

pour info, je ne vaux pas faire comme ça:

Private Sub TextBox15_Change()

    Dim valeur As Byte
    TextBox15.MaxLength = 10 'nbr caractère max
    valeur = Len(TextBox15)    If valeur 2 Or valeur 5 Then TextBox15 = TextBox15 & "/"
    TextBox15.AutoTab = True 'autotabulation

End Sub

merci par avance

2 réponses

PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
24 déc. 2008 à 16:07
salut,

IF condition
  action 1
SINON
  action 2
FIN

il ne faut pas forcément "quitter" (ce qui se ferait avec exit sub), le ELSE sert à ton test de condition






Private Sub 
CommandButton2_Click()

    If UserForm14.TextBox1.Text = "" Or _
       UserForm14.ComboBox1.Text = "" Or _
       UserForm14.TextBox2.Text = "" Or _
       UserForm14.TextBox3.Text = "" Or _
       UserForm14.TextBox4.Text = "" Or _
       UserForm14.TextBox5.Text = "" Or _
       UserForm14.TextBox6.Text = "" Then
        MsgBox "Remplir tous les
champs"
        UserForm14.TextBox1.SetFocus ' <-
pour revenir sur le textbox1
    Else
        '..............suite
des instructions
    End If
End Sub





<small>
[../code.aspx?ID=39466 Coloration VB6, VBA,
VBS]
</small>



++
<hr size="2" width="100%" />Prenez un instant pour répondre à [sujet-SONDAGE-POP3-POUR-CS_769706.aspx ce sondage] svp 
3
mythiac Messages postés 72 Date d'inscription mardi 23 septembre 2008 Statut Membre Dernière intervention 23 février 2009
24 déc. 2008 à 16:12
merci, j'y avais pas pensé...
0
Rejoignez-nous