avoir plusieurs MsgBox

gege21

XLDnaute Occasionnel
bonsoir a tous
j'ai un code pour changer un mot de pass
pour cela je doit entre
- Nom d'utilisateur
-Ancien mot de passe
- Prénom de votre meilleur ami (pense bête)
mais si un des 3 et faux je n'ai qu'un message d'erreur
et j'en voudrai un pour chaque

Code:
If Sheets("mot").Range("b2").Value <> txtAncienMot.Text Or Sheets("mot").Range("a2").Value <> txtNom.Text Or Sheets("mot").Range("c2").Value <> txtPrenom.Text Then
    MsgBox "L'ancien mot de passe est incorrect", vbCritical, "Ancien Mot de passe"
 

Pièces jointes

  • chanepass.xls
    53 KB · Affichages: 31
  • chanepass.xls
    53 KB · Affichages: 39
  • chanepass.xls
    53 KB · Affichages: 35

Fred0o

XLDnaute Barbatruc
Re : avoir plusieurs MsgBox

Bonsoir gege21,

Peut-être comme ceci ?
VB:
    If Sheets("mot").Range("b2").Value <> txtAncienMot.Text Then MsgBox "L'ancien mot de passe est incorrect", vbCritical, "Ancien Mot de passe"
    If Sheets("mot").Range("a2").Value <> txtNom.Text Then MsgBox "Le nom est incorrect", vbCritical, "Nom d'utilisateur"
    If Sheets("mot").Range("c2").Value <> txtPrenom.Text Then MsgBox "Le prénom est incorrect", vbCritical, "Prénom d'utilisateur"

A+
 

gege21

XLDnaute Occasionnel
Re : avoir plusieurs MsgBox

re.

après plus ample teste j'ai bien les 3 msgbox

mais par contre le reste du code ne marche plus
 

Pièces jointes

  • chanepass.xls
    63.5 KB · Affichages: 40
  • chanepass.xls
    63.5 KB · Affichages: 39
  • chanepass.xls
    63.5 KB · Affichages: 42

Fred0o

XLDnaute Barbatruc
Re : avoir plusieurs MsgBox

Bonjour,

Avec ceci, cela devrait fonctionner.
VB:
Private Sub cmdOK_Click()
'verification ancien mot de passe
    If Sheets("mot").Range("b2").Value <> txtAncienMot.Text Then
        MsgBox "L'ancien mot de passe est incorrect", vbCritical, "Ancien Mot de passe"
        txtAncienMot = ""
        txtAncienMot.SetFocus
        Exit Sub
    End If
    If Sheets("mot").Range("a2").Value <> txtNom.Text Then
        MsgBox "Le nom est incorrect", vbCritical, "Nom d'utilisateur"
        txtNom = ""
        txtNom.SetFocus
        Exit Sub
    End If
    If Sheets("mot").Range("c2").Value <> txtPrenom.Text Then
        MsgBox "Le prénom est incorrect", vbCritical, "Prénom d'utilisateur"
        txtPrenom = ""
        txtPrenom.SetFocus
        Exit Sub
    End If
    'enregistrement
    With Sheets("mot")
        .Range("a2").Value = txtNom
        .Range("b2").Value = txtNouveauMot
        .Range("c2").Value = txtPrenom
    End With
    MsgBox "Enregistrement avec succès", vbInformation, "Changement"
    txtNom = ""
    txtAncienMot = ""
    txtNouveauMot = ""
    txtPrenom = ""
    txtNom.SetFocus
End Sub

A+
 

Discussions similaires

Statistiques des forums

Discussions
311 733
Messages
2 082 011
Membres
101 866
dernier inscrit
XFPRO