Maybe a look in my code could clear it a bit:
'builds the contextmenu with values from Taxis i.e. a table former set.
Sub AddKontextMenu()
i = 1
Dim myBar As CommandBar
Dim myBttn As CommandBarButton
CommandBars("myKontext").Delete
On Error GoTo handler
Set myBar = Application.CommandBars.Add("myKontext", msoBarPopup)
Do Until IsEmpty(Taxis.Cells(i, 1))
Set myBttn = myBar.Controls.Add
myBttn.Caption = Taxis.Cells(i, 1).Value
myBttn.OnAction = frmNeuerAuftrag.GetKontextChoice(myBttn.Index)
i = i + 1
Loop
Exit Sub
handler:
Resume
End Sub
' when Listbox lstAktAuftraege receives a dblclick we show the contextmenu
Private Sub lstAktAuftraege_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
CommandBars("myKontext").ShowPopup
MsgBox "TEST"
End Sub
' the menuconstruction is done in UserForm_Initialize()
'with
auto_öffnen.AddKontextMenu
'and when dblclicked following function is called:
Function GetKontextChoice(cab As Integer)
MsgBox "Taxi " & CStr(cab)
End Function
this ends up, that when the form initializes I get the msgbox for each entry
in the according table,
but not, when the listfield is dblclicked. the line MsgBox "TEST" displays
after dblclick but with some unreasonable delay.
When I set a braekpoint at CommandBars("myKontext").ShowPopup then with
pressing F8 I can see the contextmenu, but not without that.....
lost in depair....