473,388 Members | 1,277 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Right Click Context menu: Only Cut, Copy, Paste

TheSmileyCoder
2,322 Expert Mod 2GB
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.

8 19604
Rabbit
12,516 Expert Mod 8TB
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
32,556 Expert Mod 16PB
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
2,322 Expert Mod 2GB
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
2,322 Expert Mod 2GB
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
32,556 Expert Mod 16PB
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
32,556 Expert Mod 16PB
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
2,322 Expert Mod 2GB
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
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

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

Similar topics

3
by: Leon | last post by:
Is it possible? Say We have a list of suppliers link like A supplier B supplier when right click on a supplier, a context menu(that has "details","view products", etc) appears and click...
7
by: Bani | last post by:
Is it possible to get browser-menu events (IE) into Javascript? I have a special copy/paste on the onkeydown event (ctrl+c/ctrl+v). Now the users would like to trigger it also from the browser...
5
by: Add and Paste | last post by:
Dear Access developers, I have a lot of cut and pasting to do from Excel to an Access form. But instead of just pasting, I want to "add then paste" the value. Does anybody have a way to do this?...
3
by: VM | last post by:
How can I display my own popup menu when a user right-clicks inside the form? I know you use context menus but I don't how to implement them. Thanks.
0
by: VM | last post by:
I'm having a synchronizaition problem when I display a right-click popup mouse and when I have the code that checks where in the row the user clicked in order to mark the whole line. With the...
1
by: T.H.M | last post by:
Hello I create a datagrid(C# visual studio .net , aspx file) with a few column. One of the column is button column, linkButton type. In run time when I click on the data in the column with right...
3
by: Robert | last post by:
I have downloaded the demo from MS. There is this code in the control: ' Enable or disable IE's context menu? This allows the parent host ' to render its own. Public Property...
1
by: Preeti | last post by:
Hi all I am a fresher and have been given a requirement in VB.net I have to make an application in VB.net which will run as a system tray icon and will add one or two items in the default...
1
by: uday1302 | last post by:
I have 30 buttons and I am trying to implement context menu on each button click by using following method. void OnButtonClick(object sender, EventArgs e) { Button btn =...
0
by: WillChapman | last post by:
Hello charitable, I have a repetitive task that requires the user to go to a command prompt, navigate to a folder (usually deep in the system), and perform a syntax scan on a file (with an in-house...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.