Helle there,
I found this code in the net and copied it to my current project in ms access ( I am a beginner ) however there is one particular line that is not working. I want lo load navigation form when the user login is successful but nothing is happening no matter how many times I click the okay button. can somebody help figure out the error in the code?
Thanks!
I found this code in the net and copied it to my current project in ms access ( I am a beginner ) however there is one particular line that is not working. I want lo load navigation form when the user login is successful but nothing is happening no matter how many times I click the okay button. can somebody help figure out the error in the code?
Code:
Option Compare Database
Private intLogAttempt As Integer
Private Sub cboUser_AfterUpdate()
txtPassword.SetFocus
End Sub
Private Sub cboUser_GotFocus()
cboUser.Dropdown
End Sub
Private Sub cmdExit_Click()
Response = MsgBox("Do you want close this application?", vbYesNo + vbQuestion, "Quit Application")
If Response = vbYes Then
Application.Quit
End If
End Sub
Private Sub cmdLogin_Click()
Call Login
End Sub
Private Sub cmdLogin_Enter()
Call Login
End Sub
Public Sub Form_Load()
' txtFocus.SetFocus 'txtFocus is a textbox control with height, widht and positions set to zero
End Sub
Public Sub Login()
On Error GoTo ErrorHandler:
If IsNull([cboUser]) = True Then 'Check UserName
MsgBox "Username is required", vbExclamation, "Emerging Market Service Dept Database"
ElseIf IsNull([txtPassword]) = True Then 'Check Password
MsgBox "Password is required"
Else
'Compare value of txtPassword with the saved Password in tblUser
If Me.txtPassword.Value = DLookup("Password", "tblUsers", "[UserName]='" & Me.cboUser.Value & "'") Then
strUser = Me.cboUser.Value 'Set the value of strUser declared as Global Variable
strRole = DLookup("Role", "tblUsers", "[UserName]='" & Me.cboUser.Value & "'") 'set the value of strRole declared as Global Variable
DoCmd.Close acForm, "frmLogin", acSaveNo
MsgBox "Welcome Back, " & strUser, vbOKOnly, "Welcome"
DoCmd.OpenForm "frmNavigation", acNormal, "", "", , acNormal
Else
MsgBox "Invalid Password. Please try again.", vbOKOnly, "Invalid Password"
intLogAttempt = intLogAttempt + 1
txtPassword.SetFocus
End If
End If
'Check if the user has 3 wrong log-in attempts and close the application
If intLogAttempt = 3 Then
MsgBox "You do not have access to this database.Please contact admin." & vbCrLf & vbCrLf & _
"Application will exit.", vbCritical, "Restricted Access!"
Application.Quit
End If
ErrorHandler:
End Sub