Retrieve entries stored in a combo

X

XP

I need to retrieve all the current entries in a combo box; by that I mean the
list of entries currently stored in the drop down.

Is there a way to do this neatly in an array using a single line a code? Or
must I devise a loop?

Either way could someone please post example code? Thanks.
 
K

Klatuu

Depending on what you are trying to do, it may not be necessary. You can
retrieve any item in the list using the ListIndex propertry.
= Me.MyCombo.ItemData(0)
Will return the first item in the list.

The ListCount property will tell you how many items are in the list. so the
last item would be
= Me.MyCombo.Itemdata(Me.MyCombo.ListCount - 1)

So, in reality, you already have them in an array.
If for any reason you have to have them in an array:
(Note, you will need to Dim the Array at the Module level.)

Dim aryComboList(1) As String

Here is a routine that will load the combo items into an array

Private Sub Build Array()
Dim intItems As Integer
Dim intCtr as Integer

intItems = Me.MyCombo.ListCount - 1
ReDim aryComboList(intItems)

For intCtr = 0 to intItems
aryComboList(intCtr) = Me.MyCombo.ItemData(intCtr)
Next intCtr

End Sub
 
Top