Storing the results of a list box
While trying this I came up with very similar code to what William
Benson had. In order to have the first form see the array, I had to
declare it public in a code module, like Public Ar() As String . Not
sure if there is any other way. Couldn't make it public in a form.
Sometimes if I need data to be shared, I store it to cells in a
worksheet, then every module, form and control can see it.
To re-populate the listbox with the results, try this
'Somewhere in the first form, before showing the second form.
'Note that the array must have been redim'ed and have values.
Dim i As Integer
if <condition to repopulate list box then
Form2.ListBox1.Clear
For i = 1 To UBound(Ar)
Form2.ListBox1.AddItem (Ar(i))
Next
endif
Form2.Show
Len
Simon Shaw wrote:
This doesn't work as he Listbox is a multiselect.
I also want to be able to re-populate the listbox with the previous
selection if the user opens the second userform again.
Thanks
|