Combo_Box/List_Box Populating

R

Rob Rusnak

I have created a form which uses Drop-Down lists (Combo or list box) and am trying to find a way to populate the list with selections for the user. I know in VB you can uses Additem but the word document control does not seem to have the same functionality. Any help that can be provided would be greeatly appreciated.
 
C

Charles Maxson

Rob,

There is a difference in forms in documents vs. forms in VBA. From a MS
User Form 2.0 (uh... VBA Dialog) you can add items to a list box with the
AddItem method like this:

Private Sub UserForm_Initialize()
With cboList '//the list box object
.AddItem ("Item 1")
.AddItem ("Item 2")
.AddItem ("Item 3")
.AddItem ("Item 4")
End With
End Sub


BUT if you are adding controls on the Word document itself, it is (of course
:s) different; where you use the Add method using its Name parameter


Sub FormFieldAdd()
With ActiveDocument.Range.FormFields(1).DropDown.ListEntries
.Add Name:="Item 1"
.Add Name:="Item 2"
.Add Name:="Item 3"
.Add Name:="Item 4"
End With
End Sub

Bizarre but true....

--
Charles
www.officezealot.com


Rob Rusnak said:
I have created a form which uses Drop-Down lists (Combo or list box) and
am trying to find a way to populate the list with selections for the user. I
know in VB you can uses Additem but the word document control does not seem
to have the same functionality. Any help that can be provided would be
greeatly appreciated.
 
R

Rob Rusnak

Tried to run the program but keep getting "The requested member of the collection does not exist" error. I wrote the code as per controls in a word document below. Not sure how the code relates to the combo_box (in my program is cboTest)

----- Charles Maxson wrote: ----

Rob

There is a difference in forms in documents vs. forms in VBA. From a M
User Form 2.0 (uh... VBA Dialog) you can add items to a list box with th
AddItem method like this

Private Sub UserForm_Initialize(
With cboList '//the list box objec
.AddItem ("Item 1"
.AddItem ("Item 2"
.AddItem ("Item 3"
.AddItem ("Item 4"
End Wit
End Su


BUT if you are adding controls on the Word document itself, it is (of cours
:s) different; where you use the Add method using its Name paramete


Sub FormFieldAdd(
With ActiveDocument.Range.FormFields(1).DropDown.ListEntrie
.Add Name:="Item 1
.Add Name:="Item 2
.Add Name:="Item 3
.Add Name:="Item 4
End Wit
End Su

Bizarre but true...

--
Charle
www.officezealot.co


Rob Rusnak said:
I have created a form which uses Drop-Down lists (Combo or list box) an
am trying to find a way to populate the list with selections for the user.
know in VB you can uses Additem but the word document control does not see
to have the same functionality. Any help that can be provided would b
greeatly appreciated
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top