How do I disable toolbars but allow copy/paste right click?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • damicomj
    New Member
    • Sep 2010
    • 34

    How do I disable toolbars but allow copy/paste right click?

    I am trying to disable the menus for non-admin users. I have done this successfully but the copy/paste functions (by right-clicking in a textbox) do not work. I have tried enabling the Menu Bar, but this still isn't working.

    Traditional Control + C and Control + V work fine. It is the right-clicking the doesn't come up.

    Code:
    If adminRights = True Or userii = "mjdamico" Then 'Set Admin rules
        For i = 1 To CommandBars.Count
        CommandBars(i).Enabled = True
        Next i
        
        DoCmd.SelectObject acTable, , True
        DoCmd.SetWarnings True
    
    Else 'Set non-Admin rules
        For i = 1 To CommandBars.Count
        CommandBars(i).Enabled = False
        Next i
        
        DoCmd.SelectObject acTable, , True
        DoCmd.RunCommand acCmdWindowHide
        DoCmd.ShowToolbar "Menu Bar", acToolbarYes
        DoCmd.SetWarnings False
    End If
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    To Enable/Disable the Right-Click Shortcut Menus for a specific Form, you can modify the Value (True/False) of the ShortCutMenu Property of that Form. In your case:
    Code:
    Me.ShortcutMenu = (adminRights = True Or userii = "mjdamico")
    1. This Value can be set for all Forms if necessary.
    2. You can set this Property Globally in your StartUp Database Options (AllowShortcutM enus), but I do believe that once you initially set it, you must exit the DB to take effect from that point on.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #3
      I don't know of any way (I suspect there is none) to allow only specified, individual, options from the right-click menu. It is either enabled or not as far as I'm aware.

      Comment

      • Hennepin
        New Member
        • Oct 2009
        • 25

        #4
        I have Access 2007 but this worked for 2000. Set a reference to the Microsoft Office 12.0 Object Library. The 12.0 will change depending on version. I believe the function only needs to be run once and the menu will be stored with your database. Set ShortcutMenuBar property of the control to name of command bar. It should be in a drop down list in design view.
        Then enable disable as ADezii stated.

        Code:
        Option Compare Database
        Option Explicit
        
        Public Function CreateCustomMenus()
        On Error Resume Next
            CommandBars("SFDrawing_Dwg").Delete ' not sure if this needed
            Dim cmbBtn As CommandBarButton
            Dim cmb As CommandBar
            
            Set cmb = CommandBars.Add("SFDrawing_Dwg", msoBarPopup, False, False)
            With cmb
                .Controls.Add msoControlButton, 210, , , True   '210     Sort Ascending
                .Controls.Add msoControlButton, 211, , , True   '211     Sort Descending
                .Controls.Add msoControlButton, 21, , , True  ' Cut
                .Controls.Add msoControlButton, 19, , , True  ' Copy
                .Controls.Add msoControlButton, 22, , , True  ' Paste
                Set cmbBtn = .Controls.Add(msoControlButton, , , , True)
                With cmbBtn
                    .Caption = "View Pdf"
                    .OnAction = "=fncOnActinBtn3()"
                    .BeginGroup = True
                End With
            End With
        
            Set cmb = Nothing
        End Function
        '21      Cut
        '19      Copy
        '22      Paste
        '
        '539     New Record
        '644     Delete Record
                
        '210     Sort Ascending
        '211     Sort Descending
        '640     Filter By Selection
        '605     Remove Filter / Sort
                
        '247     page Setup
        '4       Print
        '258     Send Email
        
        
        Public Function fncOnActinBtn3()
            Dim ctlCurrentControl As control
            Dim strControlName As String
            Set ctlCurrentControl = Screen.ActiveControl
            strControlName = ctlCurrentControl.Name
            get_spdf_files Nz(ctlCurrentControl.Value, "") 'Function tells operating system to open pdf file
        End Function

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32633

          #5
          It looks like that flexibility is built into Access (Office generally I suspect) MJ (Thanks due to Hennepin for that illuminating piece of code). Now the problem is that your question is pretty unclear. What (clearly) are you hoping to achieve? You explain what isn't working, but even that is vastly unclear as there is no discernable context within which to make sense of it.

          Comment

          • damicomj
            New Member
            • Sep 2010
            • 34

            #6
            I am trying to get the right-click menu to pop-up when the mouse is right-clicked inside of any textbox (like it normally does). The problem is, I am disabling (or hiding, I am unsure) all of the toolbars for non-admin users. Per my research, I understand that if all of the toolbars are disabled, this also disables the right click menu.

            That is why I added this line of code back in to re-enable the right click menus, which was unsuccessful.

            Code:
            DoCmd.ShowToolbar "Menu Bar", acToolbarYes

            Comment

            • ADezii
              Recognized Expert Expert
              • Apr 2006
              • 8834

              #7
              @damicomj:
              The specific Shortcut Menu that you wish to control can be viewed via:
              Code:
              View ==> Toolbars ==> Customize ==> Select Shortcut Menus ==> on Shortcut Menus ==> Form ==> Form View Control
              Disable ALL Commandbars except this one, then selectively Enable/Disable it depending on who is Logged On.

              ----------------------------------------------------------------------------------

              The following Code should Enable the Right-Click Shortcut Menu, within the context of a Text Box (Form View Control), only for the Admin User. The Code is easily adaptable for other Users also:
              Code:
              Dim cmd As CommandBar
              
              For Each cmd In Application.CommandBars
                cmd.Enabled = (cmd.Name = "Form View Control" And CurrentUser = "Admin")
              Next
              P.S. - I didn't have the time to extensively test this, ergo the reason for the should in BOLD.

              Comment

              • damicomj
                New Member
                • Sep 2010
                • 34

                #8
                ADezii, I got an error on line 1: User-defined type not defined

                Comment

                • ADezii
                  Recognized Expert Expert
                  • Apr 2006
                  • 8834

                  #9
                  You need to set a Reference to the Microsoft Office XX.X Object Library:
                  Code:
                  In Code Window ==> Tools ==> References ==> Select Microsoft Office XX.X Object Library ==> OK

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32633

                    #10
                    So, you want right-click menus and the main Menu still available, but all the other visible toolbars not to be.

                    I suspect ADezii's instructions should be enough then. Hennepin mentioned the reference to the Microsoft Office XX.X Object Library in post #4. Let us know how you get on with it.

                    Comment

                    • ADezii
                      Recognized Expert Expert
                      • Apr 2006
                      • 8834

                      #11
                      @NeoPa:
                      I interpret this as a very specific Request, namely:
                      Disabling ALL Menus for Non-Admin Users NOT (adminRights = True Or userii = "mjdamico"), while at the same time Enabling the Right-Click, Shortcut Menu for Text Boxes. The actual Code should be (not as previoously indicated):
                      Code:
                      Dim cmd As CommandBar 
                        
                      For Each cmd In Application.CommandBars 
                        cmd.Enabled = (cmd.Name = "Form View Control" And NOT (adminRights = True Or userii = "mjdamico")) 
                      Next

                      Comment

                      • NeoPa
                        Recognized Expert Moderator MVP
                        • Oct 2006
                        • 32633

                        #12
                        You may be right ADezii. My attempts to get the OP to clarify have been somewhat unsuccessful so far. Your code example seems quite clear though, so hopefully can be manipulated by them to fit whatever their actual requirement is without any trouble.

                        Comment

                        • damicomj
                          New Member
                          • Sep 2010
                          • 34

                          #13
                          ADezzi and NeoPa,

                          My apologies for not being able to clarify the problem. ADezzi's solution has solved the problem for now, until I have the access to fully test. If it wasn't for both of your hard work, I would be stuck in never-never-land.

                          Thanks again!

                          Comment

                          • ADezii
                            Recognized Expert Expert
                            • Apr 2006
                            • 8834

                            #14
                            @damicomj:
                            I sure that I can speak for NeoPa as well as for myself in stating that we were both glad to assist you in this matter. One other small point that I would like to make is that you can also Enable/Disable Options within this Shortcut Menu. Suppose that you wanted to disable the Filter By Selection and Filter Excluding Selection Options on the Shortcut Menu when you Right-Click in a Text Box:
                            Code:
                            With Application.CommandBars("Form View Control")
                              .Controls("Filter By Selection").Enabled = False
                              .Controls("Filter Excluding Selection").Enabled = False
                            End With

                            Comment

                            Working...