Bonjour à tous,
une autre solution:
Private Sub CommandButton1_Click()
Dim sel As Range, sel2 As Range
Set sel = Sheets("Utilisateur").Cells.Find(Me.TextBox1.Value, , xlValues, xlWhole)
Set sel2 = Sheets("Utilisateur").Cells.Find(Me.TextBox2.Value, , xlValues, xlWhole)
If sel Is Nothing Then
MsgBox "Utilisateur inexistant ou mot de passe erroné"
Else
If sel2 Is Nothing Then
MsgBox "Utilisateur inexistant ou mot de passe erroné"
Else
If sel.Row = sel2.Row Then ' si sur même ligne
MsgBox "Bienvenue !"
Sheets("Menu").Range("F3").Value = TextBox1.Value
Unload Me
Sheets("Menu").Activate
Else
MsgBox "Utilisateur inexistant ou mot de passe erroné"
End If
End If
End If
End Sub
ou bien
Private Sub CommandButton1_Click()
Dim sel As Range, sel2 As Range
Set sel = Sheets("Utilisateur").Cells.Find(Me.TextBox1.Value, , xlValues, xlWhole)
Set sel2 = Sheets("Utilisateur").Cells.Find(Me.TextBox2.Value, , xlValues, xlWhole)
If sel Is Nothing Then
MsgBox "Utilisateur inexistant ou mot de passe erroné"
Exit Sub
End If
If sel2 Is Nothing Then
MsgBox "Utilisateur inexistant ou mot de passe erroné"
Exit Sub
End If
If sel.Row = sel2.Row Then ' si sur même ligne
MsgBox "Bienvenue !"
Sheets("Menu").Range("F3").Value = TextBox1.Value
Unload Me
Sheets("Menu").Activate
Else
MsgBox "Utilisateur inexistant ou mot de passe erroné"
End If
End Sub
A+