PDA

View Full Version : [SOLVED] Addling to a multi column listbox with VBA



Sean_OL
07-13-2005, 08:44 AM
I have built a form that allows a user to search a data sheet, and display the results in a listbox, however I am having a bit of trouble getting the results to display in the best way.

The results from the search a poplulated into an array which I then can populate the listbox with by using:
lstResults.list = arrSites.

However the array has empty rows at the end, so the list box is populated with empty data after the first few records.

I have tried to use the .Additem method instead, but I do not know how to use this for a multi column listbox (Site Name, Site ID, State etc.)

Should I just be happy I have the results showing, and ignore the empty rows, or is there some other way to populate the listing?

Sean

Bob Phillips
07-13-2005, 09:20 AM
I have built a form that allows a user to search a data sheet, and display the results in a listbox, however I am having a bit of trouble getting the results to display in the best way.

The results from the search a poplulated into an array which I then can populate the listbox with by using:
lstResults.list = arrSites.

However the array has empty rows at the end, so the list box is populated with empty data after the first few records.

I have tried to use the .Additem method instead, but I do not know how to use this for a multi column listbox (Site Name, Site ID, State etc.)

Should I just be happy I have the results showing, and ignore the empty rows, or is there some other way to populate the listing?

Sean

An example


Dim ary, i, j
ary = [{"Bob","M", 123;"Lynne","F",898;"Amy","F",543}]
With ListBox1
For i = 1 To 3
.AddItem ary(i, 1)
For j = 2 To 3
.List(.ListCount - 1, j - 1) = ary(i, j)
Next j
Next i
End With

Sean_OL
07-14-2005, 08:04 AM
That is exactly what I needed, thanks a million.

sheeeng
07-15-2005, 08:35 AM
An example


Dim ary, i, j
ary = [{"Bob","M", 123;"Lynne","F",898;"Amy","F",543}]
With ListBox1
For i = 1 To 3
.AddItem ary(i, 1)
For j = 2 To 3
.List(.ListCount - 1, j - 1) = ary(i, j)
Next j
Next i
End With



Great! :thumb
I never thought of adding manually by code..