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

Dropdown Word

Status
Not open for further replies.

MaddogC

Programmer
Dec 4, 2003
134
0
0
GB
Struggling to do something very simple.

I want to additems to a combo box when I open a word document.

my code, which doesn't work is as follows. Could someone tell me where i'm going wrong please.:

Private Sub Document_Open()
Me.ComboBox1.AddItem ("item 1")
Me.ComboBox1.AddItem ("item 2")
Me.ComboBox1.AddItem ("item 3")

End Sub
 
Where do you have this ComboBox1? On a UserForm?

I would also suggest:
Code:
Private Sub Document_Open()

With Me.ComboBox1
   .AddItem ("item 1")
   .AddItem ("item 2")
   .AddItem ("item 3")
End With

End Sub

---- Andy
 
This is exactly what I have. No, i'm not using a userform.
 
Then Me will not work. Me is a userform identifier.

Remove the Me. If the combobox is actually named Combobox1:
Code:
With ComboBox1
   .AddItem "item 1"
   .AddItem "item 2"
   .AddItem "item 3"
End With
should work. You can use the brackets, or not. You do not actually need them, but it will work either way.

Gerry
My paintings and sculpture
 

In a Document_Open routine in the ThisDocument class module, Me refers to the Document. If the routine is in your document than I can see no reason why the code shouldn't work; if it is in the template then Me will refer to the template and the code will probably not do what you want.

You don't say what the problem is ("doesn't work" doesn't really help much) but you need to make sure you reference the combobox correctly according to where it is and where the code is. ActiveDocument.ComboBox1 will probably do it.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top