Question
April 2, 2008 at 06:57 AM
mark_j

Looping Through Combo Boxes in word VBA

by mark_j . Updated 17 years, 7 months ago

Hi,

I have been asked to create a questionare that will contain various different combo boxes. In total I have about 150 combo boxes, 60 of which will be “Yes/No” combo’s.

The combo boxes in question are cmbProdDescA1 to cmbProdDescA60.

How do I populate this range of combo’s with the same details.

I know how to do it the long way but it is vary long winded.

Private Sub YESNO_Open()
Dim vYesNos, vYesNoss
vYesNoss = Array(“Yes”, “No”) ‘This names the items in the array

For Each vYesNos In vYesNoss
cmbProdDescA1.AddItem vYesNos
cmbProdDescA2.AddItem vYesNos
cmbProdDescA3.AddItem vYesNos
cmbProdDescA4.AddItem vYesNos
…….
cmbProdDescA60.AddItem vYesNos
Next
End Sub

I was thinking of doing something that would be much shorter like:
Private Sub Document_Open()
i = 0
Do While i <= 60 i = i + 1 Set object = ActiveDocument.ProdDescA(i) Call Fill(object) Loop End Sub Private Sub Fill(object) With object .AddItem "yes" .AddItem "no" End With End Sub Unfortunately this code does not work. If anyone could help at all I would really appreciate it Thanks MJ

This discussion is locked

All Comments