How do I populate the Column Headers in the drop-down section of a
multi-column combobox? This is the combobox used in Access 2000. I
referenced the Microsoft Forms 2.0 Object Library to include it in my
VB app. I set the ColumnHeads property to True, but I can't assign a
value to each header unless it's bound (then it's automatically the
field name). I am not a fan of bound controls.
This very similar problem was posted in this very group about 4 years
back but the solution that is mentioned is not applicable it seems. Any
help will be helpful.
mattcannen - 22 Mar 2005 23:33 GMT
Try this I used a listbox but this should be the same.
Sub PopulateListFromRecordset(lstList As ListBox, rsRecordset As
ADODB.Recordset, intNumCols As Integer)
Dim intCounter As Integer
Dim strItem As String
Dim strFill As String
strFill = "Column title1;Column Title2;"
With lstList
.RowSource = ""
.ColumnCount = intNumCols
.RowSourceType = "Value List"
.ColumnHeads = True
Me!Your combo/listbox name here.ColumnWidths = "3 cm; 1.8 cm;"
End With
'add all of the values in the recordset to the list box
Do Until rsRecordset.EOF
'for each item in the current record, build string
For intCounter = 0 To intNumCols - 1
strItem = strItem & rsRecordset(intCounter).Value & ";"
strFill = strFill & rsRecordset(intCounter).Value & ";"
Next intCounter
lstList.AddItem (strItem)
strItem = ""
rsRecordset.MoveNext
Loop
Me.YourformName.RowSource = strFill
Exit Sub
End Sub