Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    marisacoul is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jun 2017
    Posts
    27

    Disabling Shortcut Menus but Enabling Copy and Paste

    Hi there!



    I've searched the internet for this but none of the code seems to work for me. I disabled shortcut menus/full menus for users and I left them enabled for the administrators. So far I have...

    Dim i As Integer
    For i = 1 To CommandBars.Count
    CommandBars(i).Enabled = False
    Next i

    Which works fine for the users, but it also disables Copy/Cut/Paste. How do i re-enable this? This is very important for my database. I know we could use Cntl+C but there must be a way to enable them.

    Thanks in advance!

    Marisa

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    you'll need to create your own commandbars to just include those commands you want.

    See this link which is at the bottom of this thread

    https://www.accessforums.net/showthread.php?t=48595

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    And this one about ribbon customization https://www.accessforums.net/showthread.php?t=45826
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    marisacoul is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jun 2017
    Posts
    27
    I've tried this code before; it doesn't work for me. I get the error "user-defined type not defined".

    Also, is it possible to create two different shortcut menus (one for users and one for admins) for the same form? I'd like the admins to have all the controls available and users just to have copy/cut/paste.

    Marisa

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Provide code for analysis.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    marisacoul is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jun 2017
    Posts
    27
    Here's my login form code:

    Private Sub Form_Load()

    Dim i As Integer
    For i = 1 To CommandBars.Count
    CommandBars(i).Enabled = False 'all toolbars disabled for everyone: users and admins
    Next i

    End Sub

    Private Sub Command4_Click()
    On Error GoTo Command4_Click_Err


    If IsNull(Me.Password) Or Me.Password = "" Then
    MsgBox "You must enter a password."
    Exit Sub
    End If

    If (Username = "User" And Password = "user1") Then 'user
    DoCmd.RunCommand acCmdCloseWindow
    DoCmd.ShowToolbar "Ribbon", acToolbarNo
    DoCmd.OpenForm "Add New Story", acNormal, "", "", acEdit, acNormal
    Beep
    MsgBox "You have successfully logged into HomeBase as a user.", vbOKOnly, ""
    DoCmd.OpenQuery "Contacts Extended", acViewNormal
    'the users still have all toolbars disabled but now can't copy, cut, or paste



    ElseIf (Username = "Admin" And Password = "admin1") Then 'admin
    DoCmd.RunCommand acCmdCloseWindow
    DoCmd.OpenForm "Add New Story", acNormal, "", "", acEdit, acNormal
    Beep
    MsgBox "You have successfully logged in to HomeBase as an admin.", vbOKOnly, ""
    DoCmd.SelectObject acTable, , True
    'this will enable all menu bars and tool bars, which is fine. I want admins to have full control
    Dim i As Integer
    For i = 1 To CommandBars.Count
    CommandBars(i).Enabled = True
    Next i

    Else
    Beep
    MsgBox "Incorrect username or password!", vbCritical, ""
    End If

    End Sub

    Here's the code I tried to use for the shortcut menu that gave me the error:

    Sub CreateSimpleShortcutMenu()
    Dim cmbShortcutMenu As Office.CommandBar 'this is where I'm getting the error. A lot of people seem to get this error, and selecting 15.0 reference library does not help

    ' Create a shortcut menu named "SimpleShortcutMenu.
    Set cmbShortcutMenu = CommandBars.Add("SimpleShortcutMenu", msoBarPopup, False, True)

    ' Add the Remove Filter/Sort command.
    cmbShortcutMenu.Controls.Add Type:=msoControlButton, ID:=19

    ' Add the Filter By Selection command.
    cmbShortcutMenu.Controls.Add Type:=msoControlButton, ID:=21

    ' Add the paste By Selection command.
    cmbShortcutMenu.Controls.Add Type:=msoControlButton, ID:=22

    ' Add the delete By Selection command.
    cmbShortcutMenu.Controls.Add Type:=msoControlButton, ID:=478

    Set cmbShortcutMenu = Nothing

    End Sub

  7. #7
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    try

    Dim cmbShortcutMenu As Object

  8. #8
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    I get the error "user-defined type not defined".
    This is a references error. You need a reference to "Microsoft Office xx.0 Object Library".

  9. #9
    marisacoul is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jun 2017
    Posts
    27
    Yup, I've tried that.

  10. #10
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    ContextMenu.zip

    Attachment 29510Attachment 29511


    This should work. You can copy the menu from this DB to your DB (first image), then the menu should be available to any form in your DB (second image).
    This takes care of the message for the right click. I haven't investigated switching it on or off depending on user login.

  11. #11
    marisacoul is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jun 2017
    Posts
    27
    Yup, I've already referenced the 15.0 Object library.

  12. #12
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    But is it the right object library? It must be "Office", not "Access".

  13. #13
    marisacoul is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jun 2017
    Posts
    27
    Hmmm... I'm getting the message: Access can't find the object "MyMenu".

  14. #14
    marisacoul is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jun 2017
    Posts
    27
    Yes! With a bit of tweaking it worked. I've made MyMenu the default shortcut menu for the entire database. THANK YOU SO SO MUCH. Now when I present the database to my managers it'll be one I'm proud of. Thanks so much.

  15. #15
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    Glad it worked for you. It's a tricky area of Access to work with.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. field enabling and disabling
    By koncreat in forum Forms
    Replies: 16
    Last Post: 02-13-2017, 10:05 PM
  2. Enabling and Disabling Buttons on a Form.
    By Slurry Pumper in forum Forms
    Replies: 10
    Last Post: 11-14-2016, 10:07 AM
  3. Replies: 1
    Last Post: 11-25-2014, 01:42 PM
  4. Enabling and disabling fields
    By SgtSaunders69 in forum Programming
    Replies: 9
    Last Post: 12-27-2011, 06:11 PM
  5. Disabling and Enabling subforms
    By vt800c in forum Programming
    Replies: 3
    Last Post: 05-24-2011, 07:37 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums