tags:

views:

1516

answers:

2

I am attempting to do this using an MS Access 2003 application using VBA. I would like to right click on an MS Access form and have the default menu appear, as well as some options I want to add. I would like the added options to execute some function when clicked.

Any ideas?

+2  A: 

In order to replace the default shortcut menu with a menu that includes the default actions plus your custom actions, you have to create a custom shortcut menu that includes the default actions. There is no way to extend the default shortcut menu.

Shortcut menus in Access 2003 and before are a special kind of toolbar. You create them the same way (more or less) that you create a custom toolbar. The UI is kind of weird, though, as there's a special place where you create them.

To get started, right click the toolbar in your front-end Access MDB. Choose CUSTOMIZE. In the list of Toolbars, check off SHORTCUT MENUS. This will give you a list of all the built-in shortcut menus, except that they don't actually end up looking like that in real use. For instance, if right click on a form, you get this shortcut menu:

Form Design
Datasheet View
PivotTable View
PivotChart View
Filter By Form
Apply Filter/Sort
Remove Filter/Sort
Cut
Copy
Paste
Properties

Now, where is this menu on the shortcut menu? Well, this one happens to be the FORM VIEW TITLE BAR menu, even though it pops up any time you click anywhere other than on a control on the form. So, if that's the menu you want to alter, you could edit it by adding menu items to it (a drag-and-drop operation).

I think it's actually better (as I said above) to create a custom shortcut menu that replicates the built-in menu and add your enhancements because this allows you to retain the Access default shortcut menu while also having your customized version of it for use when you want it. In that case, you'd need to start a new shortcut menu, and here's where the UI is weird:

You click on the last choice on the shortcut menu, CUSTOM. You see it drops down a placeholder. You can't drag/drop to it. Instead, you have to click NEW in the main toolbar editing window and create a new shortcut toolbar (give it the name you want your custom shortcut menu to have). Your new toolbar now shows up in the list of toolbars. Highlight it and click PROPERTIES, and change the type to POPUP. This will give you an informative warning that this alteration changes it from a toolbar to a shortcut menu. You can then close your toolbar/shortcut menu's properties sheet, and now if you check off SHORTCUT MENUS again and look at the CUSTOM menu, you'll see your newly-created menu. Now you can drag and drop the menu items for the built-in menu to your new menu -- but don't drop them on the menu itself, but on the placeholder in the flyout from the > to the right of the menu name.

You can then drag and drop any options you want from any menus or toolbars to your custom menu.

I assume you know how to use the shortcut menu, as it's part of the properties sheet of all form objects.

UPDATE 2009/05/21: The official Access 2007 blog just posted an article on doing this programmatically in Access 2007. Because of the ribbon interface, there are going to be differences, but some things will be the same.

David-W-Fenton
Does Access use Office.CommandBar and Office.CommandBarButton objects, as per Excel, Word, etc?
onedaywhen
David, This is very helpful in understanding how Access goes about dealing with Command Bar's. However, I am looking to do what you stated programmatically.
Curtis Inderwiesche
It's doable programmatically, but rather fussy, in my experience. In VBE help search for "program toolbars" and read the help there. Since shortcut menus are just a form of toolbar, you would use the same methods. I wouldn't do it that way myself, though. I'd create custom menus and then show/hide particular items on them as context required.
David-W-Fenton
+1  A: 

Try This

Sub Add2Menu()
  Set newItem = CommandBars("Form View Popup").Controls.Add(Type:=1)
  With newItem
    .BeginGroup = True
    .Caption = "Make Report"
    .FaceID = 0
    .OnAction = "qtrReport"
  End With
End Sub

As you can see it will add item in "Form View Popup" Command Bar and when this item is clicked it will load procedure qtrReport

And use this function to see all Commandbars in Access

Sub ListAllCommandBars()
For i = 1 To Application.CommandBars.Count
    Debug.Print Application.CommandBars(i).Name
Next
End Sub
THEn
This is exactly what I was looking for. Thanks
Curtis Inderwiesche