Discussion Locked

Password Logic

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have a password form in Access 97. I want to give 3 chances and then go back to the Main Menu. My code (below) works if you enter the correct Password (SPL. It does not work if you enter an incorrect password.

Dim passcount as integer
If me.text21 = "SPL" then
me.text21 = Null
Docmd.openform "Secretary Changes", acnormal, "", "", , acWindow Normal

Else if me.text21 <> "SPL" then
Do until passcount =3
me.text21.setfocus
me.text21 = " "
passcount = passcount + 1
Loop
end if
'go to Main Menu

4 replies

by Former member

Your Do loop never checks the condition of me.text21. I would start with the Do until and if the password is SPL or you have tried 3 times then the loop ends. Next, If passcount is less than or equal to 3 then Docmd.openform (the only way the loopcould end with a passcount of 3 or less is if me.text21="SPL").

passcount=0
Do until me.text21="SPL" OR passcount > 3
passcount= passcount+1
me.text21=Null
me.text21.setfocus
me.text21=UCase(me.text21)
Loop
If passcount<=3 then
Docmd.openform "Secretary Changes",acnormal,"","",,acWindowNormal
end if

Hope this helps, I don't have VB on this machine so I can't test the code.

by Former member

Sometimes I can make myself look really stupid. This will work.

Private Sub Command1_Click()

passcount = passcount + 1

If Text1 = "SPL" Then
Text1 = ""
DoCmd.openform "Secretary Changes",
acNormal,"","",,acWindowNormal
Else
If passcount < 3 Then
Text1 = ""
Text1.SetFocus
Else
Text1 = ""
go to Main Form
End If
End If
End Sub

This discussion is closed to new replies.