commandbar combobox and its change event 
Author Message
 commandbar combobox and its change event

 I wanted to create commandbarcombbox in document so I wrote following
coding in
"Thisdocument"(microsoft word objects) in Visual Basic editor of word.

Private Const MergeCmdBarName As String = "Set up Mail Merge"
Private WithEvents ComboBoxEvent As Office.CommandBarComboBox
Private Sub Document_Open()
End Sub
Public Sub PopulateFieldList()
    Dim db As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim cbar1 As Office.CommandBar
    Dim myControl As Office.CommandBarComboBox

    Set cbar1 = CommandBars.Add(Name:="Custom", Position:=msoBarFloating,
    cbar1.Visible = True
    Set myControl = cbar1.Controls.Add(Type:=msoControlComboBox)
    db.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=sa;Initial Catalog=Northwind;Data   Source=comp2"
    rs.Open "products", db, adOpenForwardOnly, adLockReadOnly
    For Each fld In rs.Fields
        myControl.AddItem Text:=fld.Name  'adding column names in combo box
(i.e.product id,productname etc)
    myControl.OnAction = "ComboBoxEvent_Change(myControl)"  ' calling change
event of combbox.Here I am not     'sure whether calling event of combox box
on  onaction method such way      is right  or wrong
End Sub

'change event
Private Sub ComboBoxEvent_Change(ByVal Ctrl As Office.CommandBarComboBox)
    Dim stComboText As String

    stComboText = Ctrl.Text
    MsgBox StrComboText

End Sub

When I open the document it open the document with commandbar and combobox
control with column name.But when I changes the selection in a command bar
combo box,it shows following message -
"The macro cannot be found or has been disabled because of your macro
security settings"
To avoid the above  message I set macro security as low, medium and high
also in Tools menu.But it shows me the same message whenever I try to change
the selectin in combo box.
How to solve this problem?
I also want  to ask how to call change event of command bar combobox.I
already wrote code to call change event(as mentioned above).But I am not
sure about it whether it will work or not. If not please forword me
suggestion or code.

Thu, 23 Sep 2004 19:21:08 GMT  
 [ 1 post ] 

 Relevant Pages 

1. commandbar combobox and its change event

2. ComboBox Change Event Does not fire when user changes selection

3. Help: Losing ComboBox Change event in UserControl OCX

4. Combobox control, change event

5. Change event (combobox)

6. ComboBox Change Event

7. ComboBox Change event

8. ComboBox Change event

9. Combobox List Change Event

10. combobox style2 change event

11. Speaking of Combobox Change Events...

12. Combobox.clear doesn't generate Change event


Powered by phpBB® Forum Software