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 / November 2004

Tip: Looking for answers? Try searching our database.

List Boxes in UserForms

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
blaglobal - 03 Nov 2004 23:53 GMT
Hi all,

I am new to VBA and I am trying to complete a userform in Word - using
the 'insert userform command'.  I have added a list box to the
userform but I can't type in the choices I want it to show.  Does
anyone have any ideas please?
Thanks,
blaglobal
DA - 04 Nov 2004 06:09 GMT
Hi blaglobal

Go to this page and click on the "UserForms" tab. Plenty
of good reading and info there to tell you about forms.

http://word.mvps.org/FAQs/index.htm

Good luck,
Dennis.

>-----Original Message-----
>Hi all,
[quoted text clipped - 6 lines]
>blaglobal
>.
Jay Freedman - 04 Nov 2004 20:27 GMT
> Hi all,
>
[quoted text clipped - 4 lines]
> Thanks,
> blaglobal

The general idea is to use code in either the Userform_Initialize or the
Userform_Activate procedure to load items into the list box. There are a
couple of ways to go about this.

One consideration is where the text of the items comes from. They can be
constant -- the same for all runs of the userform -- and stored directly in
the code or somewhere in the template (e.g., as AutoText or as document
variables). The simplest case would be

Private Sub UserForm_Activate()
  With ListBox1
     .AddItem "one"
     .AddItem "two"
     .AddItem "three"
  End With
End Sub

An alternative is to make a variable of type Variant, store the items in it
as an array, and assign the variable to the listbox's .List property. This
is much easier to do than to describe:

Private Sub UserForm_Activate()
  Dim temp As Variant
  temp = Array("one", "two", "three")
  ListBox1.List = temp
End Sub

When you start to deal with larger amounts of data, or with data that may
change from one run to another, you need to use other storage methods and
ways of reading the data. For example, you might store the items in a text
file, which you read with the Open and Line Input commands. They might be in
an Excel worksheet or an Access database, which offer things like ADO
(Active Data Objects) and ODBC (Open Data Base Connectivity) -- ways of
directly connecting the listbox to the data source. But that's a story for
another week...

Signature

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

 
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.