Link to home
Start Free TrialLog in
Avatar of vihaan
vihaan

asked on

MS Access Security

The below code is about security. I am disabling the tool bars if user belongs to the user group and enabling them if belongs to admins group. And I disabled F11 and shift key both irrespective of the user group. But one drawback of disabling F11 is it disables the mouse right click. if the F11 is disabled , the right click no longer works. But i added code for  the right click to work( which is on the Case "Users"). But i am not sure whether it is foolproof or not, because i got to know that on some system the right click is working and on some systemm , its not working

The other question is I would lke to disable ribbon in 2007 version , i feel the below code is working good for 2003 version of access but in 2007 there is ribbon. retaining the same below code , i need a code which disables the ribbon in ms access 2007.

I tried Docmd.showtoolbar "Ribbon" ,acToolbarNo. But i do not know some times it works and some times it does not . Do i have to be sure about the order of statements i execute in the code .

I need to disable ribbon, navigation pane and at the top the office options in 2007 So i add the code to disable all the above things. then i should not modify the code based on the version. you see. i want the same code to work on access version 2003 or above. So Please Help me .


calling the fucntion in ONCUrrent event of the startup form


Public Function mod_security()

Dim UserName As String
Dim curgroup As String
Dim GroupNames(10) As String
Dim ws As Workspace
Dim usr As User
'i will be used for dealing with the user groups ( counting the user groups, identify the group the current user belongs to)
Dim i As Integer
'j will be used for dealing with the toolbars( enabling and disabling them based on the user group)
Dim j As Integer
Dim filter As String
Const Db_Text As Long = 10
Const DB_Boolean As Long = 1
     
       'Disable the F 11 for both admin as well as users
       ChangeProperty "AllowSpecialKeys", DB_Boolean, False
       'Disalbe the Shift Key ( its another way to gain access to tables, forms, reports actually everything)
       ChangeProperty "AllowBypassKey", DB_Boolean, False
       DoCmd.RunCommand acCmdWindowHide

       'grabbing the user name of the user who logged on currently
       UserName = CurrentUser
       'DBEgine is the top level object in the hierarchy. you need to address DBEngine in order to access the users
       'in a group or connecting to a database. To get a clear picture highlight the below word "Workspaces" and hit f1
       'you will see a hierarchy of the objects and the order of access to the objects.
   Set ws = DBEngine.Workspaces(0)
   Set usr = ws.Users(UserName)

       'Put all groups user is in into an array
   For i = 0 To usr.Groups.Count - 1
       GroupNames(i) = usr.Groups(i).Name
   Next i

       'Loop through all the user groups
   For i = LBound(GroupNames) To UBound(GroupNames)
      Select Case GroupNames(i)
                  'If the user belongs to admin group, enable all the toolbars.
             Case "Admins"
                   For j = 1 To CommandBars.Count
                       CommandBars(j).Enabled = True
                       DoCmd.ShowToolbar "Menu Bar", acToolbarYes
                       DoCmd.ShowToolbar "Form Design", acToolbarYes
                       DoCmd.ShowToolbar "Formatting (Form/Report)", acToolbarYes
                   Next j
                   Exit Function
                   
                  'If the user belongs to user group, then disable all the toolbars
             Case "Users"
                   For j = 1 To CommandBars.Count
                       If InStr(CommandBars(j).Name, "Popup") = 0 Then
                          CommandBars(j).Enabled = False
                       End If
                   Next j
      End Select
   Next i

End Function


ASKER CERTIFIED SOLUTION
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial