User Security Level For Tab Control

Symon

Registered User.
Local time
Today, 20:07
Joined
Aug 20, 2014
Messages
19
Hi All,

Looking for a little help on the above topic if possible...

I have 7 tabs in a tab control and I would like each one to be editable depending on the users' security level (set by Admin)
I have managed to get the following code working for one tab, but I do not have the knowledge to make it work for the rest.

So, just trying to make things more understandable...

Tab Names:
TabUnitInformation
TabUnitHistory
TabLabelChecklist
TabTestBay
TabReturns
TabDemoStock
TabAdmin

User Security Levels and what users with those levels should be able to edit:
1. Admin - No tab restrictions
2. Test Bay - TabUnitInformation, TabLabelChecklist, TabTestBay
3. Returns - TabUnitInformation, TabReturns, TabDemoStock
4. Label - TabUnitInformation, TabLabelChecklist
5. Sales - TabUnitInformation, TabUnitHistory, TabDemoStock
6. User - TabUnitInformation
7. Technical - TabUnitInformation, TabUnitHistory

The code I have written ( which works for whichever tab control I list, but not sure how to write in more than one):

Code:
Private Sub Form_Load()
Dim Security As Integer

Me.TxtUserLogin = Environ("USERNAME")

If IsNull(DLookup("UserSecurity", "TblEmployees", "[UserLogin] = '" & Me.TxtUserLogin & "'")) Then
    MsgBox "No UserSecurity set up for this user. Please contact Administrator", vbOKOnly, "LoginInfo"
    Me.TabUnitHistory.Enabled = False
Else
   Security = DLookup("UserSecurity", "TblEmployees", "[UserLogin] = '" & Me.TxtUserLogin & "'")
   If Security = 1 Then
       Me.TabUnitHistory.Enabled = True
   
   Else
       Me.TabUnitHistory.Enabled = False
   End If

End If
End Sub

Any help with this would be great...

Thanks guys!! :D
 
Thanks for your reply Uncle Gizmo, I couldn't find anything in the code there which is referring to "protecting more than one tab control.

I though the following might work, but tried it and no joy.

Code:
Private Sub Form_Load()
Dim Security As Integer

Me.TxtUserLogin = Environ("USERNAME")

If IsNull(DLookup("UserSecurity", "TblEmployees", "[UserLogin] = '" & Me.TxtUserLogin & "'")) Then
    MsgBox "No UserSecurity set up for this user. Please contact Administrator", vbOKOnly, "LoginInfo"
    
Else
   Security = DLookup("UserSecurity", "TblEmployees", "[UserLogin] = '" & Me.TxtUserLogin & "'")
   If Security = 1 Or 5 Or 7 Then
   Me.TabUnitHistory.Enabled = True
   Else
   Me.TabUnitHistory.Enabled = False
       
   If Security = 1 Or 2 Or 4 Then
   Me.TabLabelChecklist.Enabled = True
   Else
   Me.TabLabelChecklist.Enabled = False
   
   If Security = 1 Or 2 Then
   Me.TabTestBay.Enabled = True
   Else
   Me.TabTestBay.Enabled = False
   
   If Security = 1 Or 3 Then
   Me.TabReturns.Enabled = True
   Else
   Me.TabReturns.Enabled = False
   
   If Security = 1 Or 3 Or 5 Then
   Me.TabDemoStock.Enabled = True
   Else
   Me.TabDemoStock.Enabled = False
   
   If Security = 1 Then
   Me.TabAdmin.Enabled = True
   Else
   Me.TabAdmin.Enabled = False
   
   If Security = 1 Or 2 Or 3 Or 4 Or 5 Or 6 Or 7 Then
   Me.TabunitInformation.Enabled = True
   Else
   Me.TabunitInformation.Enabled = False
   End If
   
End If

End Sub

Any Ideas?

Thanks again
 
issue solved...

I am however, thinking of not using "Environ" and using the API call instead, by all accounts this is is a more robust way of signing in users which log into the network.

Code:
Private Sub Form_Load()
Dim Security As Integer

Me.TxtUserLogin = Environ("USERNAME")

If IsNull(DLookup("UserSecurity", "TblEmployees", "[UserLogin] = '" & Me.TxtUserLogin & "'")) Then
    MsgBox "No UserSecurity set up for this user. Please contact Administrator", vbOKOnly, "LoginInfo"
    
Else
   Security = DLookup("UserSecurity", "TblEmployees", "[UserLogin] = '" & Me.TxtUserLogin & "'")
   If Security = 1 Or Security = 5 Or Security = 7 Then
   Me.TabUnitHistory.Enabled = True
   Else
   Me.TabUnitHistory.Enabled = False
   End If
   
   If Security = 1 Or Security = 2 Or Security = 4 Then
   Me.TabLabelChecklist.Enabled = True
   Else
   Me.TabLabelChecklist.Enabled = False
   End If
   
   If Security = 1 Or Security = 2 Then
   Me.TabTestBay.Enabled = True
   Else
   Me.TabTestBay.Enabled = False
   End If
   
   If Security = 1 Or Security = 3 Then
   Me.TabReturns.Enabled = True
   Else
   Me.TabReturns.Enabled = False
   End If
   
   If Security = 1 Or Security = 3 Or Security = 5 Then
   Me.TabDemoStock.Enabled = True
   Else
   Me.TabDemoStock.Enabled = False
   End If
   
   If Security = 1 Then
   Me.TabAdmin.Visible = True
   Else
   Me.TabAdmin.Visible = False
   End If
   
   If Security = 1 Or Security = 2 Or Security = 3 Or Security = 4 Or Security = 5 Or Security = 6 Or Security = 7 Then
   Me.TabunitInformation.Enabled = True
   Else
   Me.TabunitInformation.Enabled = False
   End If
   
End If

End Sub
 
I'm performing similar, but disallowing "buttons" based on the user Environ$("USername"). Some have up to 10 users. Is there a condensed method I could use similar to the SQL function "IN"?

For example, I am currently using:
If (Environ$("Username")) Like "chuck" Or (Environ$("Username")) Like "James" Or (Environ$("Username")) Like "William"... and so on.

Could I use something similar to If (Environ$("Username")) IN("chuck","James","William") ?

Any assistance would be greatly appreciated.
 

Users who are viewing this thread

Back
Top Bottom