Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to edit a combo box or how to insert items in a combo box?

34 views
Skip to first unread message

Mo

unread,
Oct 4, 2006, 4:16:02 PM10/4/06
to
i have created a combo box in a word doc. i would like to enter some items in
it.

for example, i would like to be able to choose my items from a drop down
menu. i don't wish to use any code as i am not a Programmer.

can you assist please.

Thank you

Jean-Guy Marcil

unread,
Oct 4, 2006, 8:35:44 PM10/4/06
to
Mo was telling us:
Mo nous racontait que :

How did you create this combo box? (What command/toolbar did you use?)
What is your overall purpose with this combo box?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarci...@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org


Mo

unread,
Oct 5, 2006, 5:55:01 PM10/5/06
to
Jean,

thanks for replying.

i have used the control box to create the combo box.
i would like to enter items in there & select them up via the drop down menu.

hope this clarifies your questions.

Thank you

Jean-Guy Marcil

unread,
Oct 5, 2006, 6:33:04 PM10/5/06
to
Mo was telling us:
Mo nous racontait que :

> Jean,


>
> thanks for replying.
>
> i have used the control box to create the combo box.
> i would like to enter items in there & select them up via the drop
> down menu.
>
> hope this clarifies your questions.

Actually, it clarifies your post... not my questions! ;-)

Here is a simple way:
While in design mode, right click on the combobox and select "View Code".
Once in the code pane, paste the first example and play around with it in
the document to see what happens.
This is fine if you only have a few items. If you have many items, you may
want to consider using an array, see the second example for that.

'_______________________________________
'Example One
Private Sub ComboBox1_GotFocus()

Dim lngCurSel As Long

With ComboBox1
'Save Current selection
lngCurSel = .ListIndex
'Remove items or we will keep adding them over an over...
.Clear
'Add the items
.AddItem "Select"
.AddItem "One"
.AddItem "Two"
.AddItem "Three"
.AddItem "Four"
'Reset the selection
.ListIndex = lngCurSel
End With

End Sub
'_______________________________________

'_______________________________________
'Example Two
Private Sub ComboBox1_GotFocus()

Dim varItems As Variant
Dim lngCurSel As Long

'Create the array
varItems = Array("Select", "One", "Two", "Three", "Four", "Five", _
"Six", "Seven", "Eight", "Nine", "Ten")

With ComboBox1
'Save Current selection
lngCurSel = .ListIndex
'Remove items or we will keep adding them over an over...
.Clear
'Add the items
.List() = varItems
'Reset the selection
.ListIndex = lngCurSel
End With

End Sub
'_______________________________________

If I may add a comment, if you plan on distributing your template/document,
avoid the ACtiveX controls from the Control Toolbox.
In Word they are unstable and if someone has their security set to High,
they will be deactivated as they are considered a virus threat (They can
activate code just by being clicked on...)

See if you can use a protected form instead.

Of course, if your projects requires macros anyway, then the security issue
becomes irrelevant. Just be aware that there have been numerous reports
describing difficult to cure problems regarding ActiveX controls. I think
three things can help you:
1) Make sure you give them a name yourself (Do not use the default name as I
did above with "ComboBox1",
2) Do not use too many of tem in one document,
3) Create the document using the lowest Word version you want to support.

Mo

unread,
Oct 8, 2006, 7:14:01 AM10/8/06
to
Jean,

Thanks for your help. It has worked.
I might need to post another question for you again.

Regards,

Mo

Selamet Gan

unread,
Oct 28, 2006, 6:59:50 AM10/28/06
to
0 new messages