PDA

Click to See Complete Forum and Search --> : [RESOLVED] How to load several comboboxes with the same list


New2vba
Jan 31st, 2006, 03:17 PM
Back again hoping to be rescued :)

I have a Word 2003 userform that contains a series of combo boxes. Six of these comboboxes contain the same (long list) of items. To load these items I am simply using the .additem method.

This works fine and I have simply copied and pasted the same code 6 times. However, I would assume that there is a better way of doing it so that I only have to write the list once, thus shortening the code? I have searched google and vba help but can find nothing.

Any ideas appreciated.

DKenny
Jan 31st, 2006, 03:32 PM
You could move the adds into a seperate procedure that take a combox as an argument and then call that proce for each of your comboboxes.

Heres some pseudo-code to get you started.

Sub main()
PopulateCombo Me.ComboBox1
PopulateCombo Me.ComboBox2
'etc
End Sub



Sub PopulateCombo(MyCombo As MSForms.ComboBox)
MyCombo.AddItem "Item1"
MyCombo.AddItem "Item2"
MyCombo.AddItem "Item3"
MyCombo.AddItem "Item4"
MyCombo.AddItem "Item5"
MyCombo.AddItem "Item6"
End Sub

New2vba
Jan 31st, 2006, 04:38 PM
Thanks (again) DKenny - worked a treat :)