P
Patrick Bastard
Hi,
I try to have 3 different passwords for 3 different users, to allow them 3
different functions.
I'd be happy if someone here could tell me why this code doesn't work, and
how to correct it.
Thanks in advance.
Patrick.
Sub TestPass()
Dim okPswd As Boolean
Dim pass(3) As String
pass(0) = "tata"
pass(1) = "titi"
pass(2) = "toto"
okPswd = GetPassword(pass(3), 3)
' MsgBox okPswd
If okPswd ="tata" Then
'**********************************************************************
'TEST CODE 1
Range("C2:H2").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
'****************************************
elsIf okPswd ="titi"Then
'**********************************************************************
'TEST CODE 2
Range("C5:H5").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
'****************************************
elsIf okPswd ="toto"Then
'**********************************************************************
'TEST CODE 3
Range("C8:H8").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
'****************************************
Else
'do something else that you want!
End If
End Sub
Function GetPassword(CorrectPswd As String, MaxTimes As Long) As Boolean
'Dave Peterson, mpep
Dim Pswd As String
Dim essais As Long
essais = 1
GetPassword = False
Do
Pswd = InputBox("Essai n°" & essais & " sur " & MaxTimes _
& ". Mot de passe?", _
"Saisie du mot de passe")
If Pswd = "" Then
Exit Function
End If
If Pswd <> CorrectPswd Then
essais = essais + 1
If essais <= MaxTimes Then
MsgBox "Erreur !"
End If
Else
GetPassword = True
'MsgBox "Mot de passe correct !"
Exit Function
End If
Loop Until essais > MaxTimes
End Function
I try to have 3 different passwords for 3 different users, to allow them 3
different functions.
I'd be happy if someone here could tell me why this code doesn't work, and
how to correct it.
Thanks in advance.
Patrick.
Sub TestPass()
Dim okPswd As Boolean
Dim pass(3) As String
pass(0) = "tata"
pass(1) = "titi"
pass(2) = "toto"
okPswd = GetPassword(pass(3), 3)
' MsgBox okPswd
If okPswd ="tata" Then
'**********************************************************************
'TEST CODE 1
Range("C2:H2").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
'****************************************
elsIf okPswd ="titi"Then
'**********************************************************************
'TEST CODE 2
Range("C5:H5").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
'****************************************
elsIf okPswd ="toto"Then
'**********************************************************************
'TEST CODE 3
Range("C8:H8").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
'****************************************
Else
'do something else that you want!
End If
End Sub
Function GetPassword(CorrectPswd As String, MaxTimes As Long) As Boolean
'Dave Peterson, mpep
Dim Pswd As String
Dim essais As Long
essais = 1
GetPassword = False
Do
Pswd = InputBox("Essai n°" & essais & " sur " & MaxTimes _
& ". Mot de passe?", _
"Saisie du mot de passe")
If Pswd = "" Then
Exit Function
End If
If Pswd <> CorrectPswd Then
essais = essais + 1
If essais <= MaxTimes Then
MsgBox "Erreur !"
End If
Else
GetPassword = True
'MsgBox "Mot de passe correct !"
Exit Function
End If
Loop Until essais > MaxTimes
End Function