How to disable navigation tab based on username/password...adding to my code.
When I open my Access database, I have a macro that opens up a username/password screen. When I enter my username and password, it opens a form that has multiple navigation tabs. Depending on the username that I use to log in, I have access to all the tabs or one of them is grayed out. The code refers to a tblSecurityLevel and tblEmployee table. Here's the video I watched to make this: https://www.youtube.com/watch?v=n7PcyO4m6ZI. After I made that form with navigation tabs, I created code to make one of those navigation tabs visible or not if the security level was row 1 (admin). Here's the video i used for that: https://www.youtube.com/watch?v=sWsTwYuWc1o. There are 4 parts to his tutorial. I have it working as he created it. However, you will see on his example, has an admin group and a user group. If a username is assigned the security level of Admin, they can see the admin navigation tab. If the username has a security level of User, they CANNOT click on the admin tab, but they can click on all others.
I am trying to figure out a way to add code to his, where i have more security levels. He only has two security levels, "Admin" and "User. In my database, I have 3 security levels for now, "Admin", "Manager" and "User". I have 4 navigation tabs..."Home", "Admin Page", "Add New Customer" and "Search Customer". I don't want all security levels to see each tab. Only certain security levels should see certain tabs. I have attached a screenshot of what I am trying to give access to by Security Level. The code in the video allows me to make the Admin Page not clickable for non-Admin security levels. But I am hoping to make a few more un-clickable based on the security levels.
On the tblSecurityLevel, row 1 is Admin. Row 2 is Manager. Row 3 is User. In the code below, where it says "If UserLevel = 1 Then", that is referring to the tblSecurityLevel row.
How would I modify this code to allow for multiple security levels and disable the tabs based on the security level and login username? Here the code:
Private Sub btnLogin_Click()
Dim UserLevel As Integer
Dim Username As String
Dim tempUsername As String
If IsNull(Me.txtUsername) Then
MsgBox "Please Enter Username", vbInformation, "Username Required"
ElseIf IsNull(Me.txtPassword) Then
MsgBox "Please Enter Password", vbInformation, "Username Required"
If (IsNull(DLookup("[Username]", "tbl1Employees", "[Username] ='" & Me.txtUsername.Value & "' And Password = '" & Me.txtPassword.Value & "'"))) Then
MsgBox "Incorrect Username or Password"
tempUsername = Me.txtUsername.Value
Username = DLookup("FirstName", "tblEmployees", "Username = '" & Me.txtUsername.Value & "'")
UserLevel = DLookup("SecurityLevel", "tblEmployees", "Username = '" & Me.txtUsername.Value & "'")
'open different form according to user level
If UserLevel = 1 Then ' for admin
You can use a code similar to this one:
Open in new window
I hope this be helpful.