Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2014
    Location
    United Kingdom
    Posts
    6

    Unanswered: User Security Level For Tab Control

    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:
    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
    I Have also Tried the following but has not worked, just need some idea on how to structure this code.

    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 help with this would be great...

    Thanks guys!!

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    tip 1) don't use environ, use the API call instead. why its more robust, less foolproof.

    tip 2) read up on if statements
    Code:
    If Security = 1 Or 5 Or 7 Then
    is not valid, whereas
    Code:
    If Security = 1 or Security = 5 or Security = 7 Then
    should work

    tip 3) consider using a bit manipulation instead
    https://www.google.co.uk/webhp?sourc...se%20operators
    specifically:- FIX: Jet drivers do not support bitwise operators

    ..set up your user security level as a number
    Code:
    Value Description
    1     Test Bay
    2     Returns 
    4     Label
    8     Sales
    16    User
    32    Technical
    128   Admin
    if a user as User and Technical clearance then their security code is 16+32
    if a user has all clearance then they have 191: 1+2+4+8+1
    6+32+128. in reality in this situation you wouldn't have admin access as all, you'd set the individual permissions. you are probably better off defining groups with the permissions, and then assign users to whatever groups are required. this means that there is less risk of permission problems as you assign a user to a predetermined group, rather than permissions to a specific user. so your groups could well be
    technical only
    technical + test

    then assign users to the group to get the permission value

    then query the table using the bitwise SQL operator to find out if that user as the specific bit set
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Aug 2014
    Location
    United Kingdom
    Posts
    6
    This is great!!!
    Thank you very much Healdem!!
    This works a treat, I will take your other suggestions on board and try to implement them.
    I am currently self teaching Access/VBA/SQL and the help from these forums is very helpful!

    Thanks Again!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •