Hi I have created a login form with user ID and the Password Text Box
The problem is that while putting the password it accepts the password o any available password and loin into the system . I am not getting how the vba code is below:
Public Sub Login()
'Option Compare Binary
Dim TempUserLogin As TempVar
On Error GoTo ErrorHandler:
If IsNull(Me.txtuserid.value) Or Me.txtuserid.value = "" Then
MsgBox "You must enter a User ID", vbOKOnly + vbInformation, "UserID Required"
Me.txtuserid.SetFocus
Exit Sub
End If
If IsNull(Me.tp.value) Or Me.tp.value = "" Then
MsgBox "You must enter a Password", vbOKOnly + vbInformation, "Password Required"
Me.tp.SetFocus
Exit Sub
End If
If (IsNull(DLookup("UserName", "tblUsers", "StrComp(UserName, '" & Me.txtuserid.value & "', 0) = 0"))) Or _
(IsNull(DLookup("Password", "tblUsers", "StrComp(Password, '" & Me.tp.value & "', 0) = 0"))) Then
Me.txtuserid.value = ""
Me.tp.value = ""
Me.txtuserid.SetFocus
intLogAttempt = intLogAttempt + 1
MsgBox "Invalid UserName Or Password!!!! Yor are left with another " & 5 - [intLogAttempt] & " Attempt to Login" & vbCrLf & "User ID and the Password both are case sensitive!!!", vbOKOnly + vbCritical, "UNAUTHORISED ACCESS"
txtuserid.value = ""
tp.value = ""
txtuserid.SetFocus
Else
TempVars!TempUserLogin = Me.txtuserid.value
strUser = Me.txtuserid.value 'Set the value of strUser declared as Global Variable
strRole = DLookup("Role", "tblUsers", "[UserName]='" & Me.txtuserid.value & "'") 'set the value of strRole declared as Global Variable
strMyname = DLookup("Uname", "tblUsers", "[UserName]='" & Me.txtuserid.value & "'")
STRUNIT = DLookup("unit", "UNIT", "[Current] = True")
DoCmd.Close acForm, Me.NAME, acSaveNo
DoCmd.OpenForm "SWITCHBOARD", acNormal
End If
'Check if the user has 3 wrong log-in attempts and close the application
If intLogAttempt = 5 Then
MsgBox "You missed five (5) times Loging Attempt,You do not have access to this Database.Please contact Admin." & vbCrLf & vbCrLf & _
"Application will Exit.", vbCritical, "Access Denied!!!!"
Application.Quit
End If
ErrorHandler:
End Sub
The problem is that while putting the password it accepts the password o any available password and loin into the system . I am not getting how the vba code is below:
Public Sub Login()
'Option Compare Binary
Dim TempUserLogin As TempVar
On Error GoTo ErrorHandler:
If IsNull(Me.txtuserid.value) Or Me.txtuserid.value = "" Then
MsgBox "You must enter a User ID", vbOKOnly + vbInformation, "UserID Required"
Me.txtuserid.SetFocus
Exit Sub
End If
If IsNull(Me.tp.value) Or Me.tp.value = "" Then
MsgBox "You must enter a Password", vbOKOnly + vbInformation, "Password Required"
Me.tp.SetFocus
Exit Sub
End If
If (IsNull(DLookup("UserName", "tblUsers", "StrComp(UserName, '" & Me.txtuserid.value & "', 0) = 0"))) Or _
(IsNull(DLookup("Password", "tblUsers", "StrComp(Password, '" & Me.tp.value & "', 0) = 0"))) Then
Me.txtuserid.value = ""
Me.tp.value = ""
Me.txtuserid.SetFocus
intLogAttempt = intLogAttempt + 1
MsgBox "Invalid UserName Or Password!!!! Yor are left with another " & 5 - [intLogAttempt] & " Attempt to Login" & vbCrLf & "User ID and the Password both are case sensitive!!!", vbOKOnly + vbCritical, "UNAUTHORISED ACCESS"
txtuserid.value = ""
tp.value = ""
txtuserid.SetFocus
Else
TempVars!TempUserLogin = Me.txtuserid.value
strUser = Me.txtuserid.value 'Set the value of strUser declared as Global Variable
strRole = DLookup("Role", "tblUsers", "[UserName]='" & Me.txtuserid.value & "'") 'set the value of strRole declared as Global Variable
strMyname = DLookup("Uname", "tblUsers", "[UserName]='" & Me.txtuserid.value & "'")
STRUNIT = DLookup("unit", "UNIT", "[Current] = True")
DoCmd.Close acForm, Me.NAME, acSaveNo
DoCmd.OpenForm "SWITCHBOARD", acNormal
End If
'Check if the user has 3 wrong log-in attempts and close the application
If intLogAttempt = 5 Then
MsgBox "You missed five (5) times Loging Attempt,You do not have access to this Database.Please contact Admin." & vbCrLf & vbCrLf & _
"Application will Exit.", vbCritical, "Access Denied!!!!"
Application.Quit
End If
ErrorHandler:
End Sub