Is there a better way?

B

BRC

I am trying to develop a routine that will present user with a list of
items which the user can select (1 or more up to about 20). Once the
user makes their selection the items will be insert as bullet-ed items
into the document. At this stage my most promising idea is to put the
items on a userform in textboxes with a check box beside each textbox.
if the user checks the checkbox that item will be added to an array.
When the user clicks a command button the contents of the array could
be inserted into the document. I am wondering if there might be a
better (simpler) way to accomplish this. Perhaps grabbing the items
from excel table or a access table?
any thoughts or suggestions would be appreciated. Thank you in advance
BRC
 
J

Jezebel

Depends on what you mean by 'best'. There are three issues ---

1. What is going to be easiest for the user? Do they need to be able to do
it, change their mind, do it again?

2. Does it need to be easy to maintain the list? Will the set of items
change very often? Do you need to be able to read the list of items form
somewhere each time the template is used? How many users will you have, on
how many different computers?

3. Do you need formatted text? Will the items have italics, bold etc?


Checkboxes on a form is reasonable. You could use the tag property of each
checkbox to store the name of an autotext item; then when OK is clicked,
iterate the checkboxes and, if checked, insert the corresponding autotext
entry.
 
C

champollion.yves

I would rather use a Listbox control, whose "ListStyle" property is set
to "1. frmListStyleOption".
This gives you an unlimited number of listed items, each with its own
checkbox - but you have only one control, it's much more lightweight
and manageable.

You populate the ListBox1 control with the "AddItem" method:

ListBox1.AddItem "Some texte here"

When you need to retrieve only those items that have been checked by
the user (perhaps when the form is being closed), you cycle through all
lthe ListBox1 items, verify their Selected() status and get their text
value, like this:

Sub GetSelectedItems()
Dim iCounter As Long
Dim sItemText As String

For iCounter = 0 To Fl1.ListCount - 1
If Fl1.Selected(iCounter) Then
sItemText = Fl1.List(iCounter)
End If
Next

End Sub

This way you can have as many items as needed, no need to add or
substract controls. IMHO, this is the canonic way of handling option
lists.

Cheers,
Yves Champollion
www.champollion.net
 
B

BRC

The list box control sounds like a good solution to my problem. You
seem to understand what I am trying to do here. Yes I want to retrieve
the checked items when the list is closed and insert them into the
document as bullet-ed or numbered items. Would you put this control on
a userform? (I have not done much with Word in the last several years
and back then Wordbasic was the language so I am kind of new to vba.)
 

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