Password Loop question.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

JE McGimpsey was kind enough to share a variant of the following code with
me for password authentication;

Const sPASSWORD As String = "****"
Dim vResponse As Variant
Do
vResponse = Application.InputBox("Please enter the password")
If vResponse = False Then Exit Sub 'User Cancelled
If vResponse <> sPASSWORD Then MsgBox "Unfortunately this is not the
correct password"
Loop Until vResponse = sPASSWORD

This is great but does anybody know how to limit this to three "loops". I
only want to give the individual inputting the password three attempts before
the application quits.

Thanks as always

Andy
 
Try:

Const sPASSWORD As String = "****"
Dim vResponse As Variant
Dim i as Integer
Do
vResponse = Application.InputBox("Please enter the password")
If vResponse = False Then Exit Sub 'User Cancelled
If vResponse <> sPASSWORD Then
MsgBox "Unfortunately this is not the
correct password"
Else
Exit Loop
EndIf
i = i+1
Loop Until i < 3
 
Back
Top