troubleshooting Question

How to disable navigation tab based on username/password...adding to my code.

Avatar of brasiman
brasiman asked on
Microsoft AccessVB ScriptVisual Basic Classic
18 Comments1 Solution242 ViewsLast Modified:
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"
    Me.txtUsername.SetFocus
ElseIf IsNull(Me.txtPassword) Then
    MsgBox "Please Enter Password", vbInformation, "Username Required"
    Me.txtPassword.SetFocus
Else
   
       
    If (IsNull(DLookup("[Username]", "tbl1Employees", "[Username] ='" & Me.txtUsername.Value & "' And Password = '" & Me.txtPassword.Value & "'"))) Then
        MsgBox "Incorrect Username or Password"
    Else
        tempUsername = Me.txtUsername.Value
        Username = DLookup("FirstName", "tblEmployees", "Username = '" & Me.txtUsername.Value & "'")
        UserLevel = DLookup("SecurityLevel", "tblEmployees", "Username = '" & Me.txtUsername.Value & "'")
        DoCmd.Close
        'open different form according to user level
            If UserLevel = 1 Then ' for admin
       
                    DoCmd.OpenForm "Dashboard"
                    Forms![Dashboard]![txtLogin] = tempUsername
                    Forms![Dashboard]![txtUser] = Username
           
            Else
                DoCmd.OpenForm "Dashboard"
                Forms![Dashboard]![txtLogin] = tempUsername
                Forms![Dashboard]!AdminTab.Enabled = False
                Forms![Dashboard]![txtUser] = Username
           
                End If
            End If
        End If
    End If

End Sub
Security-Level-and-Nav-Tabs.jpg
ASKER CERTIFIED SOLUTION
Antonio Salva Ripoll

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 18 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 18 Comments.
Try for 7 days

”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