By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,495 Members | 1,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,495 IT Pros & Developers. It's quick & easy.

Right Click Context menu: Only Cut, Copy, Paste

TheSmileyCoder
Expert Mod 100+
P: 2,321
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?
Nov 29 '11 #1

✓ answered by TheSmileyCoder

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)
Expand|Select|Wrap|Line Numbers
  1. Public Sub CreateRigthClickBar()
  2.     Dim cmbRC As CommandBar
  3.     Dim cmbButtonCopy As CommandBarButton
  4.     Dim cmbButtonCut As CommandBarButton
  5.     Dim cmbButtonPaste As CommandBarButton
  6.     Dim strBarName As String
  7.     strBarName = "CustomRightClick"
  8.  
  9.     On Error Resume Next
  10.     CommandBars(strBarName).Delete
  11.     On Error GoTo 0
  12.  
  13.     Set cmbRC = CommandBars.Add(strBarName, msoBarPopup, False)
  14.  
  15.     Set cmbButtonCopy = cmbRC.Controls.Add(msoControlButton, 21)
  16.     Set cmbButtonCut = cmbRC.Controls.Add(msoControlButton, 19)
  17.     Set cmbButtonPaste = cmbRC.Controls.Add(msoControlButton, 22)
  18.  
  19.  
  20. 'Cleanup
  21.     Set cmbRC = Nothing
  22.  
  23.     Set cmbButtonCopy = Nothing
  24.     Set cmbButtonCut = Nothing
  25.     Set cmbButtonPaste = Nothing
  26. End Sub
  27.  
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.

Share this Question
Share on Google+
8 Replies


Rabbit
Expert Mod 10K+
P: 12,315
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.
Nov 29 '11 #2

NeoPa
Expert Mod 15k+
P: 31,186
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.
Nov 29 '11 #3

TheSmileyCoder
Expert Mod 100+
P: 2,321
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.
Nov 29 '11 #4

TheSmileyCoder
Expert Mod 100+
P: 2,321
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:
Expand|Select|Wrap|Line Numbers
  1. Set cmdbarRC = Application.CommandBars.Add(strBar, msoBarPopup)
  2.   cmdbarRC.Controls.Add msoControlButton, 21 'Cut
  3.   cmdbarRC.Controls.Add msoControlButton, 19 'Copy
  4.   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.
Nov 30 '11 #5

NeoPa
Expert Mod 15k+
P: 31,186
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.
Nov 30 '11 #6

NeoPa
Expert Mod 15k+
P: 31,186
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.
Nov 30 '11 #7

TheSmileyCoder
Expert Mod 100+
P: 2,321
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)
Expand|Select|Wrap|Line Numbers
  1. Public Sub CreateRigthClickBar()
  2.     Dim cmbRC As CommandBar
  3.     Dim cmbButtonCopy As CommandBarButton
  4.     Dim cmbButtonCut As CommandBarButton
  5.     Dim cmbButtonPaste As CommandBarButton
  6.     Dim strBarName As String
  7.     strBarName = "CustomRightClick"
  8.  
  9.     On Error Resume Next
  10.     CommandBars(strBarName).Delete
  11.     On Error GoTo 0
  12.  
  13.     Set cmbRC = CommandBars.Add(strBarName, msoBarPopup, False)
  14.  
  15.     Set cmbButtonCopy = cmbRC.Controls.Add(msoControlButton, 21)
  16.     Set cmbButtonCut = cmbRC.Controls.Add(msoControlButton, 19)
  17.     Set cmbButtonPaste = cmbRC.Controls.Add(msoControlButton, 22)
  18.  
  19.  
  20. 'Cleanup
  21.     Set cmbRC = Nothing
  22.  
  23.     Set cmbButtonCopy = Nothing
  24.     Set cmbButtonCut = Nothing
  25.     Set cmbButtonPaste = Nothing
  26. End Sub
  27.  
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.
Dec 4 '11 #8

pestoking
P: 1
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.
May 1 '12 #9

Post your reply

Sign in to post your reply or Sign up for a free account.