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

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale FyeOwner, Developing Solutions LLCCommented:
1.  Here is the code that I use to disable the Ribbon in 2007:

Public Sub DisplayRibbon(Optional IsVisible As Boolean = True)

    Dim intAction As Integer
    If Application.Version <> 12 Then
        'do nothing
    ElseIf IsVisible Then
        DoCmd.ShowToolbar "Ribbon", acToolbarYes
        DoCmd.ShowToolbar "Ribbon", acToolbarNo
    End If
End Sub

2.  To display popup (shortcut) menus after disabling them on a form, I will usually use the MouseUp event of a form or a control, or the click event of a label and then syntax similar to the following to popup a custom shortcut menu.  But you could also do this for standard popup menus, if you know their name.



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.