Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2005

Tip: Looking for answers? Try searching our database.

how do i add values to a listbox control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
uizzical - 17 Mar 2005 20:39 GMT
I am trying to add a listbox Activex control to a word form.  The help text
says to set the "Displayvalues" property but when I open the properties for
the control, Displayvalues is not a listed property.
Jay Freedman - 18 Mar 2005 03:12 GMT
>I am trying to add a listbox Activex control to a word form.  The help text
>says to set the "Displayvalues" property but when I open the properties for
>the control, Displayvalues is not a listed property.

You were looking at the help for a dropdown control for a Web page.
The ActiveX control from the Control Toolbox is not at all the same
beast, so that help topic doesn't apply.

ActiveX controls can't store their values; you have to reload them
each time the user creates a new document or opens an old one. To do
that you need VBA code in the Document_New and Document_Open
procedures.

One way is to repeat the .AddItem method once for each entry you want
to add:

Private Sub Document_New()
   With ComboBox1
       .AddItem "one"
       .AddItem "two"
       .AddItem "three"
       .ListIndex = 0
   End With
End Sub

This gets pretty tedious after three or four items. Another way is to
load all the items into an array in a Variant variable, and then
assign the variable to the box's .List property:

Private Sub Document_New1()
   Dim TheList As Variant
   TheList = Array("one", "two", "three")
   ComboBox1.List = TheList
   ComboBox1.ListIndex = 0
End Sub

A variation of the .List method is to load the array from an external
data source, which can be a Word document, an Excel worksheet, a
database, etc. Sample code is shown near the end of
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnword2k2/html/
odc_activeX.asp
.

--
Regards,
Jay Freedman
Microsoft Word MVP         FAQ: http://word.mvps.org

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.