Problem with Combo Box

K

KJT

I am using Word 2003 and I have created several Combo Boxes with the
following formula:

Private Sub ComboBox1_DropButtonClick()
ComboBox1.Clear
ComboBox1.AddItem "Discuss"
ComboBox1.AddItem "Review"
ComboBox1.AddItem "Change"
ComboBox1.AddItem "N/A"
End Sub

I can bring up an item in the drop down box by typing the first letter of
the item but I am not able to bring up an item in the drop down box by
clicking on the item with my mouse. Do have something set wrong in my
properties? Please HELP!
 
J

Jezebel

You've got the code in the wrong place: you're clearing and re-loading the
combo each time you click, which clears any selection you've made. Move the
code to the form's Initialize event.
 
K

KJT

I am sorry but can you provide more detail. Again, I am very new at this.
You stated to move the code to the form's initialize event. What does this
mean? Please provide more detail.
 
K

Klaus Linke

For online forms, you often should not need any VBA code at all:
http://www.computorcompanion.com/LPMArticle.asp?ID=22

But if I double-click on a forms control in the document (or use the context
menu), the VBA editor opens and not the properties window as shown in the
link above.
If that is your problem, too, maybe someone can help us out and explain how
to get the properties window?

In VBA, you could add items to the dropdown(s) in the immediate window:
ThisDocument.ComboBox1.AddItem "Discuss"
....

Pretty clumsy, though.

Klaus
 
K

Klaus Linke

Argh, I used the Check Boxes from the "Web tools" toolbar, as you probably
did, too.

You'll likely want to change to those from the "Forms" toolbar, which are
those described in Dian Chapman's article.

Klaus
 
J

Jay Freedman

Hi KJT,

You didn't say where the combo box is, and Jezebel assumed it was on a
UserForm (a custom dialog box created in the VBA editor). But from the form
of your subroutine, it appears that you placed a combo box in the document
body from the Control Toolbox, and that has different events. Jezebel is
correct that your code is in the wrong place, but for this kind of document
the "right place" is different.

Open the code in the VBA editor. Notice the two dropdowns across the top of
the code window. Set the one on the left to the entry Document. The dropdown
on the right automatically changes to New, and VBA creates an empty Private
Sub Document_New(). Set the one on the right to Open, and VBA adds an empty
Private Sub Document_Open().

Change the name of the existing procedure from ComboBox1_DropButtonClick to
ComboBox1_Initialize. (This is not a special name like the others mentioned
here.) Then, inside each of the two empty routines, insert the name of the
initialize routine, like

Private Sub Document_New()
ComboBox1_Initialize
End Sub

This loads the items into the combo box each time a document based on this
template is created or reopened -- *not* every time the user clicks the down
arrow.

If you want the user's selection to be saved when the document is closed,
and restored each time it's opened, you have some more work to do. You can
save the selection in a document variable on exit from the combo box, and
the ComboBox1_Initialize procedure can then read the document variable (if
it exists) and set the initial selection to that value.

--
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