Addhandler problem

Joined
Aug 30, 2006
Messages
2
Reaction score
0
Hi,

I have a little(?) problem with an EventHandler. I create 79 Buttons in a For Loop and add an eventhandler to each of them. My code looks like this:

Code:
   Public Sub CreateButtons()
           For intStartIndex = intStartIndex To 79

                   oButton = CType(m_PopUp_1.Controls.Add _
                   (Office.MsoControlType.msoControlButton, Temporary:=False),_
                   Office.CommandBarButton)
                   oButton.Caption = intStartIndex
                   AddHandler oButton.Click, AddressOf oButton_Click
           Next

    End Sub

    Private Sub oButton_Click(ByVal ctrl As Office.CommandBarButton,_
    ByRef Cancel As Boolean)

        MessageBox.Show(ctrl.Caption)

    End Sub

It works almost, but the event handler only fires once - sometimes. Sometimes it doesn´t work. Can anybody help me and post some code or can tell me what the problem is?

EDIT: It´s an Outlook Add-In Created with Visual Studio 2005
 
Last edited:

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

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top