ShortCut Menu Owner

JaedenRuiner

Registered User.
Local time
Today, 09:01
Joined
Jun 22, 2005
Messages
154
Okay,
There are things that are true about programming, one primary facet is Minimalistic Code. Basic concept: never write the same thing twice. Now, I have several list boxes on different forms, and I want to provide a command bar (pop up menu, or context menu as it is called in other programming circles) that offers the add/remove/rename functionality that I've programmed in. However, I do not want to create 5 menus with the same 3 items. I just want one menu, that executes MyAdd(), MyRemove(), MyRename(), and in those functions I want to determine which listbox control on what form opened up the popup.

Now, the parent property seems to point back to the Applicaiton object, which does me now help. How can i determine what control & form opened the pop up menu.
Jaeden "Sifo Dyas" al'Raec Ruiner
 
Don't know much about menus but if the menu is actually constructed as a form then you could use OpenArgs in the OpenForm Method.

Otherwise set Global Variables with the object names before you open the menu.
 
As Galaxiom alluded to, use public defined variables. Then on the right click of the cursor in the control Using the MouseDown event to determine which mouse button was pressed you can pass the form name, control name, etc to the public variables. Then in your functions use these variables to determine the logic of your updates.
 
Hrm.

Well I ended up using that Application property of the command bar itself, attaching to the CurrentObjectName, which happens to always be the form that is active when you open the context menu. and the form's active control is the list box who's shortcut menu's been opened.
Code:
On Error GoTo DoMenuListCommand_Error
   Dim cmdBar As CommandBar
   Dim lb As ListBox
   Dim frm As Form

   Set cmdBar = CommandBars("mnuListBoxPopup")
   Set frm = cmdBar.Application.Forms(cmdBar.Application.CurrentObjectName)
   Set lb = frm.ActiveControl
   If Not IsNull(lb.Value) Then
   Select Case index
      Case 1: frm.DoAdd lb
      Case 2: frm.DoRemove lb
      Case 3: frm.DoRename lb
   End Select
   End If

On Error GoTo 0
DoMenuListCommand_Exit:
   
   Exit Sub
DoMenuListCommand_Error:
   Resume DoMenuListCommand_Exit

For each form with a listbox I code the three public methods DoAdd, DoRemove, DoRename, and those handle the form specific code.
the index property is passed to this method from 3 other methods MenuListAdd, MenuListRemove, MenuListRename etc.

Thanks
Jaeden "Sifo Dyas" al'Raec Ruiner
 

Users who are viewing this thread

Back
Top Bottom