Getting listbox items to array using access VBA

2019-05-18 07:48发布

问题:

I have a listbox in access form. it contains 18 items . How do i store those itmes into array using access vba.

回答1:

The following will pull the contents of a listbox into an array and spit back out the contents.

Dim Size As Integer
Size = Me.List0.ListCount - 1
ReDim ListBoxContents(0 To Size) As String
Dim i As Integer

For i = 0 To Size
    ListBoxContents(i) = Me.List0.ItemData(i)
Next i

For i = 0 To Size
    MsgBox ListBoxContents(i)
Next i