List Box VBA within a document

D

dave

Hello,

I would like to use a combo box in my document to allow the user to
make one selection. For example, they can choose their favorite
activity from the list. However, I don't know where to begin.

Some major questions I have are:
* how can I add items to the selection?
* what's the limit on adding items to the list? Is it 25 like the
forms list box?


Any direction is appreciated.

Thanks,

Dave O
 
J

Jay Freedman

Assuming you mean the combo box from the Control Toolbox, first read
<http://msdn2.microsoft.com/en-us/library/aa140269(office.10).aspx> to
get a feeling for what you're planning.

If the list is fixed and you don't plan to let the user enter
something that isn't listed, you'll find that an AutoTextList field is
much simpler to create and use
(http://www.word.mvps.org/FAQs/TblsFldsFms/AutoTextList.htm).

If you still want a combo box, then here are some answers:

- You put items in the list by writing VBA code that you call from
AutoNew and AutoOpen macros (or from Document_New and Document_Open
macros, which for this purpose are equivalent). The list items can be
stored in the code itself, in the template (for example, in document
variables), or externally in a database or a spreadsheet or a Word
table. The first article cited above shows how to use a database.
Because the combo box doesn't store the list data within itself, the
list must be reloaded every time a new document is based on the
template or an existing document is reopened.

- Similarly, the combo box doesn't store the user's selection when the
document is closed. If the document will only be printed and
discarded, that's fine. But if you want the selection to be stored and
reshown on the next open, you have to supply the code yourself to
store the selection in a document variable or other place. It can be
surprisingly difficult to cover all the possible ways a document could
be saved. FileSave and FileSaveAs are obvious, but there's also a
possible save when the user chooses to close the document, and there
are several ways that could occur.

- There is no documented limit on the number of items in the list. I'd
guess that the practical limit is either ~64000 items or ~64000
characters in total. Let's just say "lots".

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top