Excel vba valider si textbox non vides

Résolu
lulu37 Messages postés 80 Statut Membre -  
lulu37 Messages postés 80 Statut Membre -
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

4 réponses

  1. ccmnino Messages postés 188 Date d'inscription   Statut Contributeur Dernière intervention   52
     
    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
  2. ccmnino Messages postés 188 Date d'inscription   Statut Contributeur Dernière intervention   52
     
    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
  3. lulu37 Messages postés 80 Statut Membre 13
     
    ca n'arrete pas pour autant la macro ...
    ?
    0
  4. lulu37 Messages postés 80 Statut Membre 13
     
    Exit Sub
    Le détail qui fait toute la différence !
    Merci beaucoup ccmnino
    0