I want to create a login screen where different users are directed to different forms on successful login. The code I wrote does not open any from on successful login. I am new to access, I need help in solving this problem. Thank you in advance.
Here is the code
Code:
Option Compare Database
Private intLogAttempt As Integer
Private Sub cboUser_GotFocus()
cboUser.Dropdown
End Sub
Private Sub close_form_click()
Response = MsgBox("Do you want to close this application?", vbYesNo + vbQuestion, "Quit Application")
If Response = vbYes Then
Application.Quit
End If
End Sub
Private Sub cmdOK_Click()
Call Login
End Sub
Public Sub frm_load()
txtFocus.SetFocus
End Sub
Public Sub Login()
On Error GoTo ErrorHandler:
If IsNull([cboUser]) = True Then
MsgBox "Username is required"
ElseIf IsNull([Password]) = True Then
MsgBox "Password is required"
Else
If Me.Password.Value = DLookup("Password", "user", "[UserID]='" & Me.cboUser.Value & "'") Then
strUser = Me.cboUser.Value
strRole = DLookup("access_level", "user", "[UserID]'" & Me.cboUser.Value & "'")
DoCmd.Close acForm, "frmLogin", acSaveNo
MsgBox "Welcome Back, " & strUser, vbOKOnly, "Welcome"
DoCmd.OpenForm "admin_menu", acNormal, "", "", , acNormal
Else
MsgBox "Invalid Password. Please try again.", vbOKOnly, "Invalid Password"
intoLogAttempt = intLogAttempt + 1
Password.SetFocus
End If
End If
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