Excel vba valider si textbox non vides

Résolu/Fermé
lulu37 Messages postés 76 Date d'inscription jeudi 24 août 2006 Statut Membre Dernière intervention 8 avril 2016 - 28 août 2006 à 12:17
lulu37 Messages postés 76 Date d'inscription jeudi 24 août 2006 Statut Membre Dernière intervention 8 avril 2016 - 28 août 2006 à 13:13
Bonjour,
Comment effectuer un controle de saisie sur un formulaire à 3 textbox?
Je voudrais à la validation du formulaire, que les 3 textbox ne soient pas vides.
Si elles sont vides, que ca retourne au meme formulaire, et si non vides, que ca continue la macro de validation.
mon code actuel est le suivant :

Private Sub OK_Click()
'controle saisie des 3 criteres d identification'
If ListBoxService = "" Then
MsgBox "Vous devez renseigner les 3 critères d'identification.", 0, "Information"
End If
If TextBoxNom = "" Then
MsgBox "Vous devez renseigner les 3 critères d'identification.", 0, "Information"
End If
If TextBoxPrenom = "" Then
MsgBox "Vous devez renseigner les 3 critères d'identification.", 0, "Information"
End If

...suite macro...
UserForm1.Hide
UserForm2.Show
End Sub

du coup ca me met bien les msgbox, mais la macro continue...alors que je voudrais qu'elle s'arrete si la valeur est nulle.

J'ai essayé d'inscrire End Sub dans le corps If mais ce ne fonctionne pas non plus ...

Pouvez vous m'aider?
Merci d'avance
A voir également:

4 réponses

ccmnino Messages postés 188 Date d'inscription samedi 20 mai 2006 Statut Contributeur Dernière intervention 27 août 2010 52
28 août 2006 à 12:26
Salut!

-Modifier ton code comme ça , ajoute "Dim rien" et remplace:

Private Sub OK_Click()
Dim rien
'controle saisie des 3 criteres d identification'
If ListBoxService = rien Then
MsgBox "Vous devez renseigner les 3 critères d'identification.", 0, "Information"
End If
If TextBoxNom = rien Then
MsgBox "Vous devez renseigner les 3 critères d'identification.", 0, "Information"
End If
If TextBoxPrenom = rien Then
MsgBox "Vous devez renseigner les 3 critères d'identification.", 0, "Information"
End If

A+
1
ccmnino Messages postés 188 Date d'inscription samedi 20 mai 2006 Statut Contributeur Dernière intervention 27 août 2010 52
28 août 2006 à 13:06
Salut!

moi je utilise vb6 et non vb for office peut-étre ça:
-Essai ça:

Private Sub OK_Click()
Dim rien
'controle saisie des 3 criteres d identification'
If ListBoxService = rien Then
MsgBox "Vous devez renseigner les 3 critères d'identification.", 0, "Information"
Exit sub
End If
If TextBoxNom = rien Then
MsgBox "Vous devez renseigner les 3 critères d'identification.", 0, "Information"
Exit sub
End If
If TextBoxPrenom = rien Then
MsgBox "Vous devez renseigner les 3 critères d'identification.", 0, "Information"
Exit sub
End If
1
lulu37 Messages postés 76 Date d'inscription jeudi 24 août 2006 Statut Membre Dernière intervention 8 avril 2016 13
28 août 2006 à 12:34
ca n'arrete pas pour autant la macro ...
?
0
lulu37 Messages postés 76 Date d'inscription jeudi 24 août 2006 Statut Membre Dernière intervention 8 avril 2016 13
28 août 2006 à 13:13
Exit Sub
Le détail qui fait toute la différence !
Merci beaucoup ccmnino
0