
commandbar combobox and its change event
hi
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()
PopulateFieldList
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,
Temporary:=True)
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)
Next
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.
Thanks
devesh