again Conextmenu on a UserForm

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

Kalle

Hi again,

managed it to show custom contextmenu properly.

But the function which is associated with the contextmenu is never called.

The function is:

Function GetKontextChoice(cab As Integer)
MsgBox CStr(cab)
End Function

And in constructing the contextmenu every control added to that menu has:

WHILE ADDING
Set myBttn = myBar.Controls.Add
myBttn.Caption = Taxis.Cells(i, 1).Value
myBttn.OnAction = frmNeuerAuftrag.GetKontextChoice(myBttn.Index)
NEXT

any ideas?
 
Hi Kalle,
Function GetKontextChoice(cab As Integer)
MsgBox CStr(cab)
End Function

And in constructing the contextmenu every control added to that menu has:

WHILE ADDING
Set myBttn = myBar.Controls.Add
myBttn.Caption = Taxis.Cells(i, 1).Value
myBttn.OnAction = frmNeuerAuftrag.GetKontextChoice(myBttn.Index)
NEXT

I don't think you can do it like that, I'm afraid. You'll need to put the
function in a standard module (not the form) and use:

myBttn.OnAction = "'GetKontextChoice " & myBttn.Index & "'"

Regards

Stephen Bullen
Microsoft MVP - Excel
www.BMSLtd.ie
 
That is correct, because (as Stephen surely knows) your form
frmNeuerAuftrag is a class in its own right (i.e. a class of type
frmNeuerAuftrag) and the visible form is just one instance of this
class. VBA must allow for multiple instances of your form/class,
therefore wouldn't know which instance's GetKontextChoice method to
call. That's why the method must be in a standard module i.e. there is
only ever one instance of a standard module in a VBA project. The same
applies to other functions which require a method's address e.g. the
method specified in Excel's OnTime must be a public sub in a standard
module.

--
 
thank you Stephen and "onedaywhen".

this was it and enlarged my understanding wherefrom i didn't know that is
was so little....

Thanks!!
 

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