
commandbar combobox and its change event
Hi Steve,
Devesh's question was originally posted to the
microsoft.public.word.vba.customization newsgroup. I am not sure that he
will know to look in the vba.general newsgroup for an answer.
We certainly appreciate your attempts to provide assistance to others, but
suggest that you post into the original newsgroups from which the questions
originated so that your response will appear as a continuation of the thread
started by the question.
If you do that, your are also more likely to be of assitance to others who
may be interested in the topic.
Please post any response to the newsgroups for the benefit of others who may
also be following the thread.
Regards,
Doug Robbins - Word MVP
Quote:
> Buy and read the VBA Developer's Handbook - avail through Amazon etc.
> went like this:
> >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
> Steve Hudson, Word Heretic
> HDK List MVP
> Sydney, Australia
> Please post replies/further questions to the newsgroup so that all may
benefit.
> If I don't provide enough information, please feel free to ask for more
:-)