UserForm Kontextmenu

  • Thread starter Thread starter Kalle
  • Start date Start date
K

Kalle

Hi @ all,

wrote a little programm, where I want a contextmenu to appear when a listbox
is clicked.

I managed it to display the contextmenu filled with values form a sheet. But
can't figure out, how to deal with .Action
And I do not understand the basic principle.

any exampels out there?

Kalle
 
For commandbarbuttons
it is .onaction

just set it to the name of the macro you want to run when the button is
clicked. (assuming commandbars). If it is actually a userform, then you
would just use the events of the control.
 
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....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top