Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populate a combo box in word

Status
Not open for further replies.

maxamis4

IS-IT--Management
Apr 12, 2006
12
0
0
US
hello,

I am trying to populate combo box in using vb inside a word document. There are a few questions that I need answered to understand this process. First off my document is known as User_Setup.doc. My combo box is name cbo_Agency.

Now everytime I read online it refers to the form intialize() sub which will allow my combo box to populate. But i don't know where to find out the name of my form. Is the name of my form the document name, is there a form i have to create? I am not sure how to go about this, I am usually an access programmer so i understand vb pretty well, i am just not familiar with the word reference library.

any help would be great thanks
 
I think that what you have read online refers to a UserForm.
When in VBE (Alt+F11) menu Insert -> UserForm

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Okay alt-F11 takes me into the code view, which doesn't excactly help me with my problem. I need to find out what my form name is? Is my form name the name of the word document or is it something else. My ultimate goal is to be able to intailize my document so that the combo box populates with the values that I need.

Hope that clearifies my problem.
 
OK, seems that you've used a FORMFIELD combo.
A starting point:
With Documents("User_Setup.doc").Formfields("cbo_Agency").DropDown.ListEntries
.Add Name:="Red"
.Add Name:="Blue"
.Add Name:="Green"
End With

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hmmmm. You need to tell what KIND of combobox you are using.

If it is a formfield combobox (a dropdown formfield) then you can populate it by code with PHV's suggestion. Or you can do it manually. A formfield dropdown is placed IN the document with the Forms toolbar.

If it is a userform with a combobox on it, then you do indeed initialize with the the userform_initialize procedure.
Code:
Sub Userform_Initialize()
Dim FillErUp()
Dim var
FillErUp = Array("firstItem", "secondItem", _
    "thirdItem", "fourthItem")
For var = 0 To Ubound(FillErUp)
   cbo_Agency.Additem FillErUp(var)
Next
End Sub
If it is a userform you are talking about, open the code module for the userform, select Userform from the object dropdown (top left), and Initialize from the procedure dropdown (top right).

If it is an ActiveX combobox - placed IN the document with the Controls toolbar - then you can populate it using the Document_Open event.
Code:
Sub Document_Open()
Dim FillErUp()
Dim var
FillErUp = Array("firstItem, "secondItem", _
    "thirdItem", "fourthItem")
For var = 0 To Ubound(FillErUp)
   cbo_Agency.Additem FillErUp(var)
Next
End Sub
This will populate an ActiveX combobox (cbo_Agency) IN the document, each time the document is opened.


Surely if you "understand vb pretty well", then you can state what kind of a combobox you are using, and if it is on a userform....or not.

faq219-2884

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top