views:

170

answers:

2

I am creating a PowerPoint in which I want users to be able to select an item from a list in a combo box. Nothing needs to happen after this, it is just to provide a record, on screen, of their choice.

My problem is that I seem to either be able to populate the combo box and users can select an item but the list gets longer each time the combobox is clicked on (i.e each time it is clicked on the list gets duplicated). Or alternatively, I can clear the combo box, then populate it but in this scenario, the users choice also seems to get cleared.

VBA example 1:

Private Sub ComboBox1_DropButtonClick()
With ComboBox1
.AddItem " ", 0
.AddItem "speed", 1
.AddItem "provisionality", 2
.AddItem "automation", 3
.AddItem "replication", 4
.AddItem "communicability", 5
.AddItem "multi-modality", 6
.AddItem "non-linearity", 7
.AddItem "capacity", 8
.AddItem "interactivity", 9
End With
End Sub

VBA example 2:

Private Sub ComboBox1_DropButtonClick()
ComboBox1.Clear
With ComboBox1
.AddItem " ", 0
.AddItem "speed", 1
.AddItem "provisionality", 2
.AddItem "automation", 3
.AddItem "replication", 4
.AddItem "communicability", 5
.AddItem "multi-modality", 6
.AddItem "non-linearity", 7
.AddItem "capacity", 8
.AddItem "interactivity", 9
End With
End Sub

Can anyone help?

+2  A: 

Because you have your code in the DropButtonClick event, every time you click the dropdown, those items are being added to your combobox. Try adding some code to check if the combobox is already populated before it adds the items:

Private Sub ComboBox1_DropButtonClick()

    If ComboBox1.ListCount = 0 Then
        With ComboBox1
            .AddItem " ", 0
            .AddItem "speed", 1
            .AddItem "provisionality", 2
            .AddItem "automation", 3
            .AddItem "replication", 4
            .AddItem "communicability", 5
            .AddItem "multi-modality", 6
            .AddItem "non-linearity", 7
            .AddItem "capacity", 8
            .AddItem "interactivity", 9
        End With
    End If

End Sub

Then you don't have to clear the combobox and clear the selected item along with it.

A: 

Brilliant - that is exactly what I was after.

Thanks for your response.

Mike

Mike Toyn
Glad to hear it! Can you accept the answer so that the question gets flagged as answered?