Password Loop question.

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
 
P

P Sitaram

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top