View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips Bob Phillips is offline
external usenet poster
 
Posts: 1,726
Default XL-2003 - Class Module - Controls declared "withEvents" don't sink events..

I also found that error Michel, if you look you will have seen that I
removed the userform/class level declaration of the objBtn object (you
declared it as class and procedure level). You need the class instance, I
got this not by using your object, but by creating a collection. I did this
because I assumed that you would be adding more buttons to the event sink
(else why bother doing it?), so I set it up for you.

I am afraid I don't know of any definitive guide to this, but you might
find these posting I have made in the past useful, http://tinyurl.com/27cyuk

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Michel S." wrote in message
...
Thanks for your reply Bob,

Andy Pope found where the error was in my code.. You may take a look at
my reply to him if you are interested.

My understanding is that the collection you suggest keeps the objBtn
object in scope once the Initialize routine finishes. Am I correct ?

If this collection is another way to make the link between the class
module and the form controls (instead of the Property Set prodedure you
removed) it completely new to me. I'd be interested to learn more; if you
happen to know where I can find additional information, I'd appeciate you
let me know.

Thanks again.

Bob Phillips a exposé le 2007-02-12 :
== clsBtn Class module

Private WithEvents mCmdOk AS MSForms.CommandButton

Private Sub mCmdOk_Click()
MsgBox "Ok button clicked"
End Sub

' == User Form
Dim mcolEvents As Collection

Private Sub UserForm_Initialize()
Dim objBtn As clsBtn
Set mcolEvents = New Collection

Set objBtn = New clsBtn
Set objBtn.mCmdOk = Me.ExistingCmdBtnOnThisForm
mcolEvents.Add objBtn
End Sub

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)

"Michel S." wrote in message
...
Hello !

Given the following code :

' == clsBtn Class module

Private WithEvents mCmdOk AS MSForms.CommandButton

Public Property Set Ok (cmd AS MSForms.CommandButton)
Set mCmdOk = cmd
End Property

Private Sub mCmdOk_Click()
MsgBox "Ok button clicked"
End Sub

' == User Form
Private objBtn AS clsBtn

Private Sub UserForm_Initialize
Dim objBtn as New clsBtn
Set objBtn.Ok = Me.ExistingCmdBtnOnThisForm
End Sub

When I click on "Me.ExistingCmdBtnOnThisForm", I expect the MsgBox to
pop, but nothing happens.

Any idea why it doesn't work ?
Thanks