You're a bit short of information.
I assume the LoginPassword is typed in and the code you are trying to run occurs on the after update of that field.
Where does the Password data come from?
Here is some code I use, but there is a table of users and their passwords, and the person trying to log in has to select their name first and hence their UserID
This code is a modification of the code I use, so is not guaranteed.
-
-
Option Compare Database
-
Option Explicit
-
-
Dim Tries As Integer
-
-
Private Declare PtrSafe Function GetKeyState Lib "user32" _
-
(ByVal nVirtKey As Long) As Integer
-
-
Function GetCapslock() As Boolean
-
'Return the CapsLock Value
-
-
GetCapslock = CBool(GetKeyState(vbKeyCapital) And 1)
-
-
End Function
-
-
Private Sub LoginPassword_AfterUpdate()
-
-
Dim UserPass As String
-
-
If Nz(LoginPassword) = "" Then
-
Exit Sub
-
End If
-
-
UserPass = ELookup("LoginPassword", "Users", "UserID = " & UserID)
-
-
If StrComp(UserPass, LoginPassword, vbBinaryCompare) = 0 Then
-
Docmd.openform "form1" ' Open the menu
-
Tries = 0
-
Else
-
If GetCapslock() = True Then
-
Msgbox "The Caps Lock is on", VbInformation
-
Else
-
Mshbox "Wrong Password. - Please re-enter", VbInformation
-
End If
-
Tries = Tries + 1
-
If Tries > 3 then
-
DoCmd.Quit
-
End If
-
End If
-
-
This password check is case sensitive and gives a warning if Caps lock is on. It is also up to you what you want to do after 3 unsuccessful tries.
Phil