Click event does not fire for CommandBarButton if the button does not fit on a docked toolbar 
Author Message
 Click event does not fire for CommandBarButton if the button does not fit on a docked toolbar

I have a Visual Basic 6.0 application that creates a toolbar in
Microsoft Word 2000.  The toolbar contains several controls,
including a CommandBarButton.  I want to respond to the
CommandBarButton's Click event within my VB code.  I declare
a CommandBarButton within my VB code (withevents) and capture
the Click event for that object.  This works fine unless the
toolbar is docked and the button does not fit on the toolbar.
In this case the button can be accessed through the
[>>(More Buttons)] button on the end of the toolbar, but when
the button is clicked in this manner, the Click event does not
fire in my VB application.  Is this a bug or am I missing something?

(I am using VB 6.0 SP5 and Office2000 SP2.)

Below is sample code that will duplicate this behavior.  When Word opens,
resize the window until button 4 is no longer visible.

Private myWordApp As Word.Application
Private WithEvents myButton As Office.CommandBarButton

Private Sub Form_Load()
    Set myWordApp = New Word.Application

    myWordApp.Documents.Add

    With myWordApp.ActiveDocument.CommandBars.Add("Test", msoBarTop, , True)
        .Visible = True
    End With

    With myWordApp.ActiveDocument.CommandBars("Test")
        With .Controls.Add(msoControlButton)
            .Caption = "This is test button number 1"
            .BeginGroup = True
            .Style = msoButtonCaption
        End With
        With .Controls.Add(msoControlButton)
            .Caption = "This is test button number 2"
            .BeginGroup = True
            .Style = msoButtonCaption
        End With
        With .Controls.Add(msoControlButton)
            .Caption = "This is test button number 3"
            .BeginGroup = True
            .Style = msoButtonCaption
        End With

        Set myButton = .Controls.Add(msoControlButton)

        With myButton
            .Caption = "This is test button number 4"
            .BeginGroup = True
            .Style = msoButtonCaption
        End With
    End With

    myWordApp.Visible = True
End Sub

Private Sub myButton_Click(ByVal Ctrl As Office.CommandBarButton, _
                            CancelDefault As Boolean)
    Debug.Print "Click Event Fired"
End Sub

Thanks in advance,

Tad Smith, MCSD



Sun, 27 Mar 2005 01:28:56 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Button Click Event Not Firing !

2. ESC still fires Validating events but clicking the Cancel button does not

3. click event not firing if lost_focus is firing first

4. DoEvents not doing any events

5. MCI Control Gets Into a Tizzy - Done Events Not Being Generated

6. Click-Event does not fire

7. combo box Click event not firing

8. First Click In UserControl DataGrid Does Not Fire An Event

9. Click and MouseUp events not firing

10. TreeView Not firing click event

11. IE4.0pp2 - Radio buttons do not fire events?

12. Command Button not getting Click Event on First press

 

 
Powered by phpBB® Forum Software