Right Click Context menu: Only Cut, Copy, Paste

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    Right Click Context menu: Only Cut, Copy, Paste

    I have disabled all the menu bars including right click menus for my standard users within my application.

    However some of the users want to be able to right click a textbox and cut/copy/paste text that way. Personally I never use those, I always use Ctrl-C and ctrl-V, but I guess its a matter of preference.

    Does anyone know or have tried to make a simply right click menu, with only the options to Cut/Copy/Paste?
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    I found this on the microsoft website http://office.microsoft.com/en-us/ac...010282509.aspx. It uses macros and it's for 2007 but it's proof of concept that it can be done.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #3
      I can't find it now Smiley, but there is a thread in this forum that covered that, or a very similar, topic recently (Probably in the last month but maybe the last two). I'll look out for it, but it certainly covered enabling/disabling toolbars as well as the buttons thereon.

      Comment

      • TheSmileyCoder
        Recognized Expert Moderator Top Contributor
        • Dec 2009
        • 2322

        #4
        Hi Neo. I did read that before posting, but I will admit to finding it a bit hard to follow. As I understood it, it was about enabling that particular tool/menu bar, which includes cut/copy/paste, but also includes sorting and filtering, which I do NOT want to allow.

        Comment

        • TheSmileyCoder
          Recognized Expert Moderator Top Contributor
          • Dec 2009
          • 2322

          #5
          I found a pretty neat way of doing it. I allready knew that it is possible to create custom menus, but I didn't know that it is also possible to create menus that use existing icons/code (such as cut n paste)

          This is a bit of the code:
          Code:
          Set cmdbarRC = Application.CommandBars.Add(strBar, msoBarPopup)
            cmdbarRC.Controls.Add msoControlButton, 21 'Cut
            cmdbarRC.Controls.Add msoControlButton, 19 'Copy
            cmdbarRC.Controls.Add msoControlButton, 22 'Paste
          I will return later with the full code, once I have ironed out a few things. The neat thing is that Access does all the coding behind the events, so I dont need to worry about whether the use is trying to cut/paste in a locked field and such. All the code is allready there, I basicly just create the button.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32633

            #6
            A link would be good (for any readers too) if you have one Smiley. It also talked about the possibility of modifying an existing toolbar as well as indicating how to recognise the one used for right-clicking. I expect that would be an easier interface for users as they are already used to selecting that in that way (as you indicated in an earlier post). Worth consideration I expect.

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32633

              #7
              I wasn't too far off - It was started about six weeks ago and is How do I disable toolbars but allow copy/paste right click?. Is this the one you thought I was referring to, as there's another more recent one with very little actual code in it? Anyway, it's particularly helpful as it covers the basics of what can be done. It makes a great starting point for anyone interested in playing in that area.

              Comment

              • TheSmileyCoder
                Recognized Expert Moderator Top Contributor
                • Dec 2009
                • 2322

                #8
                This is the link to the page, at which I read about reusing existing controlbuttons:
                Custom Toolbars

                Then at this link I found the ID numbers for the cut/copy/paste buttons. Its Excel sadly (But atleast for cut/copy/paste the IDs are identical), but I've been unable to find a similar list for access.
                List of ID for control buttons (Excel)

                Now I used the following bit of code to add a custom commandbar (Im quite sure something similar could have been accomplished using the GUI)
                Code:
                Public Sub CreateRigthClickBar()
                    Dim cmbRC As CommandBar
                    Dim cmbButtonCopy As CommandBarButton
                    Dim cmbButtonCut As CommandBarButton
                    Dim cmbButtonPaste As CommandBarButton
                    Dim strBarName As String
                    strBarName = "CustomRightClick"
                    
                    On Error Resume Next
                    CommandBars(strBarName).Delete
                    On Error GoTo 0
                    
                    Set cmbRC = CommandBars.Add(strBarName, msoBarPopup, False)
                    
                    Set cmbButtonCopy = cmbRC.Controls.Add(msoControlButton, 21)
                    Set cmbButtonCut = cmbRC.Controls.Add(msoControlButton, 19)
                    Set cmbButtonPaste = cmbRC.Controls.Add(msoControlButton, 22)
                    
                
                'Cleanup
                    Set cmbRC = Nothing
                        
                    Set cmbButtonCopy = Nothing
                    Set cmbButtonCut = Nothing
                    Set cmbButtonPaste = Nothing
                End Sub
                This only needs to run once!, then the commandbar is added to database and "stays" there.

                Now remains to decide whether to activate it for the entire form, or per control. In the Other tab of properties (for both Form and controls) I simply write the name of my menu in the property ShortCut Menu Bar.

                I hope this can help others.

                Comment

                • pestoking
                  New Member
                  • May 2012
                  • 1

                  #9
                  This is a great solution. I just pasted this into my Access 2010 app, ran the code and it worked like a charm. It was especially needed because I coded out the the ribbon and menu bars. << SNIP >>

                  Anyway, thanks again for this solution. Superb.
                  Last edited by NeoPa; May 1 '12, 10:54 PM. Reason: Removed hijack part of post. Feel free to post your questions, follow-up or from scatch, in their own threads.

                  Comment

                  Working...