469,271 Members | 1,484 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

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 8089
ADezii
8,800 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,171 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,171 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,800 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,800 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,171 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,800 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,171 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,800 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

Post your reply

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

Similar topics

4 posts views Thread by Brian Keating | last post: by
3 posts views Thread by Ryan Joseph So | last post: by
7 posts views Thread by lgbjr | last post: by
1 post views Thread by Lloyd Dupont | last post: by
7 posts views Thread by Steve | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.