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
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
-Mike Kapnisakis, Warner Bros
With your subscription - you'll gain access to our exclusive IT community of thousands of IT pros. You'll also be able to connect with highly specified Experts to get personalized solutions to your troubleshooting & research questions. It’s like crowd-sourced consulting.
We can't always guarantee that the perfect solution to your specific problem will be waiting for you. If you ask your own question - our Certified Experts will team up with you to help you get the answers you need.
Our certified Experts are CTOs, CISOs, and Technical Architects who answer questions, write articles, and produce videos on Experts Exchange. 99% of them have full time tech jobs - they volunteer their time to help other people in the technology industry learn and succeed.
We can't guarantee quick solutions - Experts Exchange isn't a help desk. We're a community of IT professionals committed to sharing knowledge. Our experts volunteer their time to help other people in the technology industry learn and succeed.