title: right click menu in popup form
body: <p>I'm new to this great forum.
  I'm trying to do right click menu on listbox.
  currently i'm trying to implement a right click menu which will show a simple messege box.</p>
  
  <p>My problem is that the list box is on a pop up form which opened up maximized. Now when i'm right clicking on the list box i see the right click menu but when i'm clicking on one of the menu options, nothing happenning (it seems that it don't go to the function as it should). i've also putted breakpoints on the function but it never tips.</p>
  
  <p>It's important to mention that if i'm setting the form popup option to no the right click menu works perfectly (when i'm clicking on one of the options i see its matching messege box).</p>
  
  <p>I'm running the following vba code:</p>
  
  <p>This is the mouse up event handler for my list box:</p>
  
  <pre><code>Private Sub Song_List_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  
  ' Call the SetUpContextMenu function to ensure it is setup with most current context
  ' Note: This really only needs to be setup once for this example since nothing is
  ' changed contextually here, but it could be further expanded to accomplish this
  SetUpContextMenu
  ' See if the right mouse button was clicked
  If Button = acRightButton Then
  'DoCmd.CancelEvent
  CommandBars("MyListControlContextMenu").ShowPopup
  End If
  End Sub
  </code></pre>
  
  <p>setting up the "SetUpContextMenu" sub:</p>
  
  <pre><code>Public Sub SetUpContextMenu()
  ' Note: This requires a reference to Microsoft Office Object Library
  Dim combo As CommandBarControl
  
  ' Since it may have been defined in the past, it should be deleted,
  ' or if it has not been defined in the past, the error should be ignored
  
  On Error Resume Next
  CommandBars("MyListControlContextMenu").Delete
  On Error GoTo 0
  
  ' Make this menu a popup menu
  With CommandBars.Add(Name:="MyListControlContextMenu", Position:=msoBarPopup)
  
  ' Provide the user the ability to input text using the msoControlEdit type
  Set combo = .Controls.Add(Type:=msoControlEdit)
  combo.Caption = "Lookup Text:" ' Add a label the user will see
  combo.OnAction = "=getText()" ' Add the name of a function to call
  
  ' Provide the user the ability to click a menu option to execute a function
  Set combo = .Controls.Add(Type:=msoControlButton)
  combo.BeginGroup = True ' Add a line to separate above group
  combo.Caption = "Lookup Details" ' Add label the user will see
  combo.OnAction = "=LookupDetailsFunction()" ' Add the name of a function to call
  
  ' Provide the user the ability to click a menu option to execute a function
  Set combo = .Controls.Add(Type:=msoControlButton)
  combo.Caption = "Delete Record" ' Add a label the user will see
  
  combo.OnAction = "=DeleteRecordFunction()" ' Add the name of the function to call"
  combo.SetFocus
  combo.Visible = True
  End With
  
  End Sub
  </code></pre>
  
  <p>setting up the all 3 function which shows different messege boxes on click:</p>
  
  <pre><code>Public Function getText() As String
  
  getText = CommandBars("MyListControlContextMenu").Controls(" Lookup Text:").Text
  
  ' You could optionally do something with this text here,
  ' such as pass it into another function ...
  MsgBox "You typed the following text into the menu: " &amp; getText
  
  End Function
  
  Public Function LookupDetailsFunction() As String
  
  LookupDetailsFunction = "Hello World!"
  
  MsgBox LookupDetailsFunction, vbInformation, "Notice!"
  
  End Function
  
  Public Function DeleteRecordFunction()
  
  ' If Not IsNull(Forms!MyFormName.Controls("Song_List").Colu mn(0)) Then
  MsgBox "Record Deleted"
  ' End If
  
  End Function
  </code></pre>