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 / August 2007

Tip: Looking for answers? Try searching our database.

combo box list data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
OTWarrior - 15 Aug 2007 16:47 GMT
I was using a form field drop down box, but I have reached the 25 limit.
Since word has no way around this, I having to use a combobox.

However, under the properties I am unable to see what generates the list in
the combobox.

Also, how do I generate the list in a macro?

NB: I am not using a userform as the microsoft support pages keeps saying, as
this is a document for people who are not on my network to use, not a program
for my own use. Having an mdb file with the values is not an option.

I have searched this site for any answers, and yet to find what I need, so
any input would be appreciated.
Jay Freedman - 15 Aug 2007 17:36 GMT
First consideration: A combobox or anything else from the Controls Toolbox
may behave badly. Read the "Appropriateness for Task" section of Cindy
Meister's article at
http://msdn2.microsoft.com/en-us/library/aa140269(office.10).aspx to see if
you can tolerate the shortcomings. IMHO you'd be much better served with a
userform (more about that in a bit).

Although Cindy's article, like whatever you read about userforms, shows how
to populate the combobox list from a database, that isn't necessary for
either a combobox or a userform. You can have the list data literally in the
macro itself, or stored as document variables or custom properties in the
document or its template, or in a separate Word document or Excel
spreadsheet or even a plain text file -- and I probably left out a few other
ways.

Here's a simple example: If this macro is in the ThisDocument module of the
document or of the template the document is based on, running it will put
the three strings into the combobox:

Sub demo()
   Dim data As Variant
   data = Array("one", "two", "three")
   ComboBox1.List = data
   ComboBox1.ListIndex = 0
End Sub

Instead of the Array statement, you can use various VBA algorithms to read
the data from wherever you chose to store it.

One thing to know: When you save and/or close the document containing the
combobox, it does _not_ store either the list or the index of the selected
item. Your code must do that. Typically, the code to populate the list is in
an AutoOpen or Document_Open macro so it runs each time the document is
reopened. The combobox's Change event handler has to store the list index of
the selected item, probably in a document variable, and the list-populating
macro needs to read that list index (if it exists) and set the .ListIndex
property to that value, so it appears to the user as if their previous
selection is still selected.

Regarding a userform: As I said before, a database is _not_ a requirement;
the data can be stored directly in the document and read by the macro that
displays the userform. Compared to the Control Toolbox's combobox, the
userform has the advantages that its display is stable, it uses much less
disk space and memory, and you don't have a big down-arrow button that also
prints with the document.

Typically you have a text form field whose entry macro displays the
userform, and the userform writes the selected value back into the form
field. That value will be saved with the document, and the macro can use it
to re-select in the list of the userform's control. (You might want to use a
listbox instead of a combobox there.) An alternative is for the userform to
write its result to a document variable, and have a DocVariable field in the
document to display its value.

Both Control Toolbox controls and userforms have a problem with the Word
security mechanism: If the security level is set to High or Very High, the
macros won't run. Also, if there are any controls in the document, then the
document opens in Design Mode and displays the toolbox, which is quite
confusing to most users.

Signature

Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

> I was using a form field drop down box, but I have reached the 25
> limit. Since word has no way around this, I having to use a combobox.
[quoted text clipped - 11 lines]
> I have searched this site for any answers, and yet to find what I
> need, so any input would be appreciated.
OTWarrior - 28 Aug 2007 10:30 GMT
Ta for reading my post and fully understanding my requirements, however here
is a solution I came up with as a work around to the problem:

http://www.officekb.com/Uwe/Forum.aspx/word-program/958/form-field-drop-down-25-
limit-list-I-have-made-a-fix-of-sorts#76c655d6f15bfuwe

 
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.