How could I make a ListBox with all the information in a DataRecordset? I have tried listbox1.RowSource="nameofthedatarecordset", but it fails.
And Moreover, how could i filter that information? I mean, if my datarecordset has 10 rows and 10 columns, how could i add to my listbox only, for example, the rows 3,5,8 and the columns 1,2,3,5?
Thanks
Did you find a solution? If you search the forum for Listbox, there are quite a few topics on this.
The following code snippet is taken from a prior effort. It shows some syntax that can be used. While the code is incomplete, it outlines the steps to create a listbox, format the column widths, add titles to the columns and then enter the data. The specific case is attached. The Visio file demonstrates searching a page and finding the connectivity to a selected shape. The results are presented in a listbox.
In your case, you need to extract the desired data items, and then systematically add them to the listbox.
Dim Lindx As Integer 'Listbox row counter
Lindx = 0
'Initialize Listbox: Definitions: Userform = conLstFrm; Listbox = ConList
conLstFrm.ConList.Clear
conLstFrm.ConList.ColumnCount = 4
conLstFrm.ConList.ColumnWidths = "180;120;120;180"
With conLstFrm.ConList 'First row is header info, Lindx = 0, column numbering begins with 0, not 1
.AddItem
.List(Lindx, 0) = "Title1" 'Note, replace "TitleX" with meaningful heading
.List(Lindx, 1) = "Title2"
.List(Lindx, 2) = "Title3"
.List(Lindx, 3) = "Title4"
End With
Lindx = 1 'Set listbox row count to 1
'Populate the Listbox: this would be inside some sort of loop. with Lindx incrementing. The "data(N)" values have been previously assigned somehow.
With conLstFrm.ConList
.AddItem
.List(Lindx, 0) = data1
.List(Lindx, 1) = data2
.List(Lindx, 2) = data3
.List(Lindx, 3) = data4
End With
Lindx = Lindx + 1
conLstFrm.show
Be sure to check out the other listbox posts.
HTH
Wapperdude
I finally got a solution. In my recordset, I have an ID column. So using that ID I identify what rows do I want. Once I got it, I create a matrix with the rows. Finally, I use the property Listbox.List = MyMatrix to fill the ListBox.
It is not elegant, but it does work.
Thanks ;D