Click to See Complete Forum and Search --> : Using CommandBarComboBox Control Change Event in Office/Word


rahul_goel607
September 20th, 2002, 02:26 PM
Hi All,

I need to handle CommandBarComboBox_Change Event in my code, But When I am trying to access the "Ctrl" value passed as a parameter. The Application is hanging and I am getting the attached error basically "The word is busy, Please retry".

Environment:
Office 2000 & VB 6.0

Code
====
<Class Module>
Private WithEvents ComboBoxEvent As Office.CommandBarComboBox

Public Sub SyncBox(box As Office.CommandBarComboBox)
Set ComboBoxEvent = box
If Not box Is Nothing Then
MsgBox "Synced " & box.Caption & " ComboBox events."
End If

End Sub

Private Sub Class_Terminate()
Set ComboBoxEvent = Nothing
End Sub
Private Sub ComboBoxEvent_Change(ByVal Ctrl As Office.CommandBarComboBox)
Dim stComboText As String

stComboText = Ctrl.Text

Select Case stComboText
Case "First Class"
FirstClass
Case "Business Class"
BusinessClass
Case "Coach Class"
CoachClass
Case "Standby"
Standby
End Select

End Sub
Private Sub FirstClass()
MsgBox "You selected First Class reservations"
End Sub
Private Sub BusinessClass()
MsgBox "You selected Business Class reservations"
End Sub
Private Sub CoachClass()
MsgBox "You selected Coach Class reservations"
End Sub
Private Sub Standby()
MsgBox "You chose to fly standby"
End Sub

<Form Module>
Option Explicit
Private ctlComboBoxHandler As New Class1
Public oWord As Word.Application
Private Sub Command1_Click()
Set oWord = New Word.Application
oWord.Visible = True
AddComboBox
End Sub
Sub AddComboBox()
Dim newBar As Office.CommandBar
Set newBar = oWord.CommandBars.Add(Name:="Test CommandBar", Temporary:=True)
Dim newCombo As Office.CommandBarComboBox
Set newCombo = newBar.Controls.Add(msoControlComboBox)
With newCombo
.AddItem "First Class", 1
.AddItem "Business Class", 2
.AddItem "Coach Class", 3
.AddItem "Standby", 4
.DropDownLines = 5
.DropDownWidth = 75
.ListHeaderCount = 0
End With
ctlComboBoxHandler.SyncBox newCombo
newBar.Visible = True
End Sub