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

What is wrong with procedure that fills combo boxes???

Status
Not open for further replies.

Paladyr

Programmer
Apr 22, 2001
508
US
cmbAnswer, cmbAnswer1 are all the names of the list boxes. Every time I try to run it, it gives me a Run time error '424' object required. What am I doing wrong? Also, how do I reference the combo box from a module or something outside the document. It is something like:

ActiveDocument.?.cmbAnswer?????? I thought that might be the problem, but couldn't figure out how to reference it. Thanks for the help, below is the code.

Sub FillComboBoxes()
'
' FillComboBoxes Macro
' Macro created 08/20/2001 by Steve Ryan
'
FillComboBox (cmbAnswer)
FillComboBox (cmbAnswer1)
FillComboBox (cmbAnswer2)
FillComboBox (cmbAnswer3)
FillComboBox (cmbAnswer4)
FillComboBox (cmbAnswer5)
FillComboBox (cmbAnswer6)
FillComboBox (cmbAnswer7)
FillComboBox (cmbAnswer8)
FillComboBox (cmbAnswer9)

End Sub

Sub FillComboBox(cmbName As ComboBox)
cmbName.AddItem "1"
cmbName.AddItem "2"
cmbName.AddItem "3"
cmbName.AddItem "4"
cmbName.AddItem "5"
cmbName.AddItem "6"
cmbName.AddItem "7"
End Sub
 
Workaround, still need to know how to reference a combo box from a module:

For intCounter = 1 To 7 Step 1
cmbAnswer.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer1.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer2.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer3.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer4.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer5.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer6.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer7.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer8.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer8.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer9.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer10.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer11.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer12.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer13.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer14.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer15.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer16.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer17.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer18.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer19.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer20.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer21.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer22.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer23.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer24.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer25.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer26.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer27.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer28.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer29.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer30.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer31.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer32.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer33.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer34.AddItem intCounter
Next
For intCounter = 1 To 7 Step 1
cmbAnswer35.AddItem intCounter
Next
 
Yes, you reference the combo box like you thought.

Example:

Private Sub GetMeTheCMBData()
for MyCycle= 1 to [red]UserForm1.ComboBox12.listCount-1[/red]
msgbox "Item Number" & MyCycle & " contains: " + _
[red]Userform1.combobox12.list(MyCycle)[/red], vbOkOnly, "What I got"
Next MyCycle
end sub

Hope this helps. It's better to have two heads to solve a problem from different angles than to have tunnel vision to a dead end.
 
Thanks for the reply! Do i just put the name of the document where you have user form, because this isn't actually a form I have created. It is just a word document with combo boxes on it. Thanks again for the help!
 
to fill a combobox you must write vba like this:

For Each Item in List
ComboBoxName.Add Item
Next Item
 
If you look above, you will see that that is not the problem. I got that to work fine, however only when it is in the VBA code contained inside the worksheet I am working with. My question is, if I am writing a macro inside a module that is outside the worksheet, how do I refer to a cell on the worksheet?
 
Sorry, you've confused me. Is it a worksheet or document you're working with? It's better to have two heads to solve a problem from different angles than to have tunnel vision to a dead end.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top