Results 1 to 2 of 2
  1. #1
    Lukael is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    239

    Custom context menu limit - only one ??

    Hi,



    I have created 3 custom context menu, for different subforms, however It seems that only one can work. Is there a limit in Access for that, or is my code wrong ?

    Here is my code ( for one of the menus, all other are basically the same):

    This code is in a module
    Code:
    Sub CreateContextMenu1()
    
        Dim cmbRightClick1 As CommandBar
        Dim cmbButton1 As CommandBarButton
        Dim cmbButton2 As CommandBarButton
        Dim MenuName As String
    
        MenuName = "ContextMenu1"
    
        ' I also tried deleting other commandbars first, but not working
        'On Error Resume Next
        'CommandBars("ContextMenu2").Delete
        'CommandBars(#ContextMenu3").Delete
    
        Set cmbRightClick1 = Application.CommandBars.Add(MenuName1, msoBarPopup, False, True)
    
        Set cmbButton1 = cmbRightClick1.Controls.Add(msoControlButton, , , , True)
             cmbButton1.Caption = "Import"
             cmbButton1.OnAction = "Import_All"
     
        Set cmbButton2 = cmbRightClick1.Controls.Add(msoControlButton, , , , True)
             cmbButton2 = "Export"
             cmbButton2.OnAction = "Exprot_All"
       
        Set cmbButton1 = Nothing
        Set cmbButton2 = Nothing
        Set cmbrightClick1 = Nothing
    
    End Sub
    And this is in a Form_Load event
    Code:
    Private Sub Form_Load()
    
    On Error Resume Next
    
    Call CreateContextMenu1
    
    End Sub
    References are set to Microsoft Office 14.0 Object library. All context menu are set to subforms controls - via property Shorcut Menu bar, after 1st time running of codes as instructed by Microsoft.


    Any help much appreciated !!!

  2. #2
    Lukael is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    239
    Solved, finally :

    Code:
    Sub CreateContextMenu1()
    
        Dim cmbRightClick1 As CommandBar
        Dim cmbButton1 As CommandBarButton
        Dim cmbButton2 As CommandBarButton
        Dim MenuName As String
    
        MenuName = "ContextMenu1"
    
      On Error Resume Next  Application.CommandBars(MenuName1).Delete
      Application.CommandBars(MenuName2).Delete
      Application.CommandBars(MenuName3).Delete
      On Error GoTo 0
    
    
        Set cmbRightClick1 = Application.CommandBars.Add(MenuName1, msoBarPopup, False, True)
    
        Set cmbButton1 = cmbRightClick1.Controls.Add(msoControlButton, , , , True)
             cmbButton1.Caption = "Import"
             cmbButton1.OnAction = "Import_All"
     
        Set cmbButton2 = cmbRightClick1.Controls.Add(msoControlButton, , , , True)
             cmbButton2 = "Export"
             cmbButton2.OnAction = "Exprot_All"
       
        Set cmbButton1 = Nothing
        Set cmbButton2 = Nothing
        Set cmbrightClick1 = Nothing
    
    End Sub
    I just had to delete all context menu when clicking on other subforms, while DB allready opened.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Custom shortcut menu ?
    By Lukael in forum Access
    Replies: 3
    Last Post: 02-08-2016, 11:50 AM
  2. Error with Custom Shortcut Menu
    By MatthewR in forum Forms
    Replies: 1
    Last Post: 09-15-2015, 01:17 PM
  3. right click context menu
    By rpeare in forum Programming
    Replies: 8
    Last Post: 10-27-2014, 11:16 AM
  4. Replies: 2
    Last Post: 05-27-2014, 11:32 AM
  5. custom shortcut menu help!
    By ninachopper in forum Access
    Replies: 5
    Last Post: 09-05-2010, 06:27 AM

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