Hello,
I am trying to create a user login form for an Access database. It will have three users and will open a different form depending on which user logs in to the database. So far I have only been able to create code which opens a single form no matter which user logs in. The code below shows the code I have made to accomplish this:
I would like to know what I would need to add to this so that a specific form would open for each user depending on the role which the user is assigned. For example, and admin user would open an admin form upon entering their password while a nurse user would see a nurse form having successfully entered their password.
Any help is appreciated.
I am trying to create a user login form for an Access database. It will have three users and will open a different form depending on which user logs in to the database. So far I have only been able to create code which opens a single form no matter which user logs in. The code below shows the code I have made to accomplish this:
Code:
Public Sub Login() On Error GoTo ErrorHandler: If IsNull([cboUser]) = True Then 'Checks username entered MsgBox "Username is required" ElseIf IsNull([txtPassword]) = True Then 'Checks validity of password entered MsgBox "Password is required" Else 'Compare password entered w/ password saved in table of users 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 & "'") DoCmd.Close acForm, "frmLogin", acSaveNo MsgBox "Welcome Back, " & strUser, vbOKOnly, "Welcome" DoCmd.OpenForm "frmPersonnelOfficer", acNormal, "", "", , acNormal Else MsgBox "Invalid Password. Please try again.", vbOKOnly, "Invalid Password" intLogAttempt = intLogAttempt + 1 txtPassword.SetFocus End If End If 'If user enters PW incorrectly three times 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
I would like to know what I would need to add to this so that a specific form would open for each user depending on the role which the user is assigned. For example, and admin user would open an admin form upon entering their password while a nurse user would see a nurse form having successfully entered their password.
Any help is appreciated.
Comment