473,324 Members | 2,246 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,324 software developers and data experts.

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.

Expand|Select|Wrap|Line Numbers
  1. If adminRights = True Or userii = "mjdamico" Then 'Set Admin rules
  2.     For i = 1 To CommandBars.Count
  3.     CommandBars(i).Enabled = True
  4.     Next i
  5.  
  6.     DoCmd.SelectObject acTable, , True
  7.     DoCmd.SetWarnings True
  8.  
  9. Else 'Set non-Admin rules
  10.     For i = 1 To CommandBars.Count
  11.     CommandBars(i).Enabled = False
  12.     Next i
  13.  
  14.     DoCmd.SelectObject acTable, , True
  15.     DoCmd.RunCommand acCmdWindowHide
  16.     DoCmd.ShowToolbar "Menu Bar", acToolbarYes
  17.     DoCmd.SetWarnings False
  18. End If
  19.  
Oct 19 '11 #1

✓ answered by ADezii

@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):
Expand|Select|Wrap|Line Numbers
  1. Dim cmd As CommandBar 
  2.  
  3. For Each cmd In Application.CommandBars 
  4.   cmd.Enabled = (cmd.Name = "Form View Control" And NOT (adminRights = True Or userii = "mjdamico")) 
  5. Next 
  6.  

13 8902
ADezii
8,834 Expert 8TB
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:
Expand|Select|Wrap|Line Numbers
  1. 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 (AllowShortcutMenus), but I do believe that once you initially set it, you must exit the DB to take effect from that point on.
Oct 19 '11 #2
NeoPa
32,556 Expert Mod 16PB
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.
Oct 19 '11 #3
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.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Public Function CreateCustomMenus()
  5. On Error Resume Next
  6.     CommandBars("SFDrawing_Dwg").Delete ' not sure if this needed
  7.     Dim cmbBtn As CommandBarButton
  8.     Dim cmb As CommandBar
  9.  
  10.     Set cmb = CommandBars.Add("SFDrawing_Dwg", msoBarPopup, False, False)
  11.     With cmb
  12.         .Controls.Add msoControlButton, 210, , , True   '210     Sort Ascending
  13.         .Controls.Add msoControlButton, 211, , , True   '211     Sort Descending
  14.         .Controls.Add msoControlButton, 21, , , True  ' Cut
  15.         .Controls.Add msoControlButton, 19, , , True  ' Copy
  16.         .Controls.Add msoControlButton, 22, , , True  ' Paste
  17.         Set cmbBtn = .Controls.Add(msoControlButton, , , , True)
  18.         With cmbBtn
  19.             .Caption = "View Pdf"
  20.             .OnAction = "=fncOnActinBtn3()"
  21.             .BeginGroup = True
  22.         End With
  23.     End With
  24.  
  25.     Set cmb = Nothing
  26. End Function
  27. '21      Cut
  28. '19      Copy
  29. '22      Paste
  30. '
  31. '539     New Record
  32. '644     Delete Record
  33.  
  34. '210     Sort Ascending
  35. '211     Sort Descending
  36. '640     Filter By Selection
  37. '605     Remove Filter / Sort
  38.  
  39. '247     page Setup
  40. '4       Print
  41. '258     Send Email
  42.  
  43.  
  44. Public Function fncOnActinBtn3()
  45.     Dim ctlCurrentControl As control
  46.     Dim strControlName As String
  47.     Set ctlCurrentControl = Screen.ActiveControl
  48.     strControlName = ctlCurrentControl.Name
  49.     get_spdf_files Nz(ctlCurrentControl.Value, "") 'Function tells operating system to open pdf file
  50. End Function
Oct 19 '11 #4
NeoPa
32,556 Expert Mod 16PB
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.
Oct 19 '11 #5
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.

Expand|Select|Wrap|Line Numbers
  1. DoCmd.ShowToolbar "Menu Bar", acToolbarYes
  2.  
Oct 20 '11 #6
ADezii
8,834 Expert 8TB
@damicomj:
The specific Shortcut Menu that you wish to control can be viewed via:
Expand|Select|Wrap|Line Numbers
  1. 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:
Expand|Select|Wrap|Line Numbers
  1. Dim cmd As CommandBar
  2.  
  3. For Each cmd In Application.CommandBars
  4.   cmd.Enabled = (cmd.Name = "Form View Control" And CurrentUser = "Admin")
  5. Next
P.S. - I didn't have the time to extensively test this, ergo the reason for the should in BOLD.
Oct 20 '11 #7
ADezii, I got an error on line 1: User-defined type not defined
Oct 20 '11 #8
ADezii
8,834 Expert 8TB
You need to set a Reference to the Microsoft Office XX.X Object Library:
Expand|Select|Wrap|Line Numbers
  1. In Code Window ==> Tools ==> References ==> Select Microsoft Office XX.X Object Library ==> OK
Oct 20 '11 #9
NeoPa
32,556 Expert Mod 16PB
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.
Oct 21 '11 #10
ADezii
8,834 Expert 8TB
@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):
Expand|Select|Wrap|Line Numbers
  1. Dim cmd As CommandBar 
  2.  
  3. For Each cmd In Application.CommandBars 
  4.   cmd.Enabled = (cmd.Name = "Form View Control" And NOT (adminRights = True Or userii = "mjdamico")) 
  5. Next 
  6.  
Oct 21 '11 #11
NeoPa
32,556 Expert Mod 16PB
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.
Oct 21 '11 #12
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!
Oct 21 '11 #13
ADezii
8,834 Expert 8TB
@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:
Expand|Select|Wrap|Line Numbers
  1. With Application.CommandBars("Form View Control")
  2.   .Controls("Filter By Selection").Enabled = False
  3.   .Controls("Filter Excluding Selection").Enabled = False
  4. End With
Oct 21 '11 #14

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

Similar topics

29
by: lori3laz | last post by:
How do you disable the right click>view source option on web pages so people can't view your coding and copy it? What's the html I need to include in my website to utilize this feature? Thank...
4
by: Brian Keating | last post by:
hi there, does anyone know how to prevent the context menu on a ToolStripText box from appearing? when i right click on the toolstriptextbox i get presented with the system undo ------ cut...
3
by: Ryan Joseph So | last post by:
On textboxes when you right click the mouse button a menu will pop-up with undo,cut,copy,paste,delete,select all. How can i disable the menu so when i right click on the textbox no menu will...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
1
by: Lloyd Dupont | last post by:
I'm implementing my own, custom, internationalized text editor. I'm trying to implement copy/paste right now. Which cause me some trouble. I'm using .NET 2.0 beta 2 (I have ordered and I'm waiting...
1
by: Mclaren | last post by:
I have this code that disables all menus and toolbars including the right click functions. Dim i As Integer For i = 1 To CommandBars.Count CommandBars(i).Enabled = False Next i How can i...
14
by: Amar | last post by:
Hi All, I am a newbie to PHP and have the task to create a page using PHP where in that page I need to disable all key operation as well as mouse operation even also the menu operation that...
7
by: Steve | last post by:
How do you disable the mouse right click to prevent pop-up window? Or if I want to have cut/copy/paste on pop-up window use same code as my custom cut/copy/paste that are triggered by toolstrip...
8
by: jh | last post by:
I'd like to copy/paste into a listbox during runtime. I can do this for a textbox but can't figure out how to accomplish this for a listbox. Any help? Thanks.
18
by: Archanak | last post by:
Hi, I have a text box and should allow user to type the text but not to allow them to copy/paste or right click. Here is the code. <html> <head> <meta http-equiv="Content-Type"...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.