locked
Access 2010 Runtime Shortcut Menu RRS feed

  • Question

  • I am having troubles getting a right click shortcut menu to display in an Access 2010 Runtime file.  I have attempted to use the code supplied at this website:

    http://msdn.microsoft.com/en-us/library/ff194247.aspx

    but it gives me an error when attempting to Set cmbShortcutMenu

    code is as follows directly from the above mentioned web site:

     
    Sub CreateSimpleShortcutMenu() 
      Dim cmbShortcutMenu As Office.CommandBar 
       
      ' 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:=605 
     
      ' Add the Filter By Selection command. 
      cmbShortcutMenu.Controls.Add Type:=msoControlButton, Id:=640 
       
      Set cmbShortcutMenu = Nothing 
       
    End Sub
    

    I am calling this from a temp form i created with a button that calls this procedure.  Maybe this is where I am going wrong?  Mostly I want to give the user the ability to right click and have access to filtering options.

    Thanks,

     

    Monday, February 14, 2011 7:54 PM

Answers

  • What error are you getting?  If you are getting:
    ---------------------------
    Microsoft Visual Basic
    ---------------------------
    Run-time error '5':

    Invalid procedure call or argument
    ---------------------------
    OK   Help  
    ---------------------------

    Then you already defined the shortcut menu.  The temporary shortcut menu exists until the container application is closed -- not the form.

    If you want to recreate the menu each time you need to put:
    On Error Resume Next
         CommandBars("SimpleShortCutMenu").Delete
    On Error GoTo 0

    Before the code to create it in case it already exists.

    • Edited by saberman Tuesday, February 15, 2011 5:24 AM Typo
    • Marked as answer by Voyagr12 Monday, February 21, 2011 2:12 PM
    Tuesday, February 15, 2011 5:23 AM

All replies

  • What error are you getting?  If you are getting:
    ---------------------------
    Microsoft Visual Basic
    ---------------------------
    Run-time error '5':

    Invalid procedure call or argument
    ---------------------------
    OK   Help  
    ---------------------------

    Then you already defined the shortcut menu.  The temporary shortcut menu exists until the container application is closed -- not the form.

    If you want to recreate the menu each time you need to put:
    On Error Resume Next
         CommandBars("SimpleShortCutMenu").Delete
    On Error GoTo 0

    Before the code to create it in case it already exists.

    • Edited by saberman Tuesday, February 15, 2011 5:24 AM Typo
    • Marked as answer by Voyagr12 Monday, February 21, 2011 2:12 PM
    Tuesday, February 15, 2011 5:23 AM
  • That is exactly the error I was receiving.  Thanks a bunch.  You just might be right.  I will check.
    Wednesday, February 16, 2011 1:33 AM
  • I used this same code to start the development of a custom shortcut menu and it worked remarkably well. After finally finding the list of control ids here, I plugged those in.  Amazingly that worked correctly as well.  But, when I tried to move the shortcut menu to apply globally to the entire database, the wheels came off the bus.  I set the shortcut menu in database options, removed the reference on my test form, and now i get no shortcut menu at all, even after restarting the database. I have tried this with and without the 'allow default shortcut menus' box checked.

    Is there something else I need to set in order to make a single shortcut menu the application default shortcut menu?


    • Edited by PaterFamilias Friday, September 14, 2012 8:31 PM corrected some header information that i did not intend to include
    Friday, September 14, 2012 8:30 PM
  • Off the top of my head I do not remember exactly what I ended up doing but I believe I just created a custom filtering area at the top of the form instead of using the built in filtering....i think.  When I have a moment I can check to confirm this.

    thanks,

    • Proposed as answer by PaterFamilias Friday, September 14, 2012 8:49 PM
    • Unproposed as answer by PaterFamilias Friday, September 14, 2012 8:50 PM
    Friday, September 14, 2012 8:38 PM
  • <object height="1" id="plugin0" style="position:absolute;z-index:1000;" type="application/x-dgnria" width="1"><param name="tabId" value="{B76D9B39-D10D-4219-990F-7F018003D236}" /></object>

    figured it out.  Two things need to happen for the 'global' short cut to take effect.  First, the form must have 'shortcut menu' property set to Yes, and second, the VBA code for the short cut menu must run before the menu is available to the forms, even though the name of the shortcut menu shows up as an option in the file/options/current database/ribbon and toolbar options/short cut menu bar dropdown after it is run the first time.

    The way I read another article, running the script just one time makes it a part of the DB for use any time thereafter.  Apparently, that is not true.  It has to run each time the DB is opened.

    And, found out that the 'allow default shortcut menus' checkbox on file/options/current database/ribbon and toolbar options has to be checked or you don't get the design tool bars when you need them.

    hummin' along again....

    Friday, September 14, 2012 8:58 PM
  • This video explained how to create custom shortcut menu and how to identify icons and their corresponding ID.

    http://www.youtube.com/watch?v=G0OetcYcbM8


    If this post answered or helped you find the answer to your question, please mark it as such for other Forum users knowledge.

    Monday, August 26, 2013 7:10 PM