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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo box in Word 2000 1

Status
Not open for further replies.

DodgyDavo

IS-IT--Management
Joined
Dec 9, 2003
Messages
11
Location
GB
Hi ive had a look through various forums and sites and tried to find help on how to create a combo box in a word document.

I have the form set up so that it opens when the template opens and other textboxs are fine. Im having trouble creating a combobox that either doesnt replicate the entire contents of the box when you choose your selection or doesnt display them at all. Please could you help me?

Below is the code that ive found that ive managed to get some results from:

Dim vColor, vColors
vColors = Array("Green", "Red", "Blue")
For Each vColor In vColors
ComboBox1.AddItem vColor
Next
ComboBox1.ListRows = 0

Whenever i choose an option it replicates the whole list of options. So a list of 3 colours ends up 4 or 5 times as big comprising of the same 3 colours.

I would like to have a set number of choices in but also allow the user to insert choices that are not their. Am i far off with the above code?

Thanks

David
 
What you are doing I think is adding the same array three times

try

Dim vColor, vColors
i=0
vColors = Array("Green", "Red", "Blue")
For Each vColor In vColors
ComboBox1.AddItem vColor(i)
i=i+1
Next
ComboBox1.ListRows = 0
 
Im now getting the error 'Type Mismatch' on the

combobox1.additem vColor (i) line.

Although the previous code did replicate it three times. as you mentioned. and more if you clicked on it again.

Its a boggle thats for sure!

DD



 
Just a thought but if you have this in combobox1_change as your macro name then it will add the items whenever you change the box. Change the macro name and run it. This should populate the combobox with just one lot of the data. Alternatively use

Dim vColor, vColors

vColors = Array("Green", "Red", "Blue")
For Each vColor In vColors
ComboBox1.RemoveItem vColor
ComboBox1.AddItem vColor

Next
ComboBox1.ListRows = 0

The above will remove the colour before adding it again.
 
May I ask why you are using ListRows = 0? ListRows is the number of lines to display. ListRows = 0 shows no items within the box.

If you put ListIndex = 0 it will display the first item in the array. Even if you want to add items (which I am not sure you are trying to do) from another text box, it will always show the first item (0) of the array. All items will display with a scroll bar if it exceeds the default number of rows (8)...or (7) from the array.

I believe dyarwood(above) is correct that your code is probably in the Combobox1_Change event. I would load the combobox with the items with the UserFrom Initialize event.

Gerry
Painting/Sculpture site:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top