views:

5

answers:

1

I have a simple COM add-in for office that I am developing (for access specifically).

I have added a custom commandbarbutton item to the context menu that pops up when you right click on an object in the navigation pane.

This works fine. The debug code I added runs (currently just a msgbox command). The one thing I cannot figure out how to do though is get an object for the object bound to the context menu.

I would like this to happen; I right click on a module in the navigation pane, select my new menu option, and then a message box appears with the name of the module that is currently highlighted. How would I go about this?

This is how I am currently handling the event:

Public Sub myEventHandler(ByVal ctrl As CommandBarButton, ByRef CancelDefault As Boolean) Handles contextMenu_navPaneObject.Click, contextMenu_navPaneList.Click

    MsgBox(Microsoft.VisualBasic.Information.TypeName(ctrl) & vbCrLf & _
           Microsoft.VisualBasic.Information.TypeName(ctrl.Parent) & vbCrLf & _
           Microsoft.VisualBasic.Information.TypeName(ctrl.Parent.Parent))

End Sub

contextMenu_navPaneObject and contextMenu_navPaneList are private objects declared using "withevents" and having an object type of commandbarbutton.

Is this the correct way to do what I want, or is there an alternative method I should be using?

A: 

Turns out to do what I wanted, I needed to run the following method:

Access.Application.CurrentObjectName()

This returned the name of the item I currently had highlighted.

I hope this helps others!

rageingnonsense