Reputation: 1686
I'm trying to add table column data as listbox items, i tried to add table column names as list box items. But how do i add table column data as listbox items. I have a table
Column1
A
B
C
D
E
I tried adding table column names as listbox items, vba
Sub item1()
On Error Resume Next
Dim i As Integer 'Index for loop
With Me.lstbox
.RowSourceType = "Value List" 'Set rowsource type
.RowSource = "" 'Clean combo contents
End With
For i = 1 To CurrentDb.TableDefs("table1").Fields.Count
Me.lstbox.AddItem (CurrentDb.TableDefs("table1").Fields(i -1).Name)
Next i
End with
End sub
How do i have A,B,C,D,E as listbox items.
Upvotes: 0
Views: 3447
Reputation: 91356
Just set the combo RowSourceType to Table / Query and either use the table name or SQL for RowSource.
With Me.lstbox
.RowSourceType = "Table/Query" 'Set rowsource type
.RowSource = "Select Field1 From Table1"
End With
Make sure you set the correct Bound Column, Column Count and Columns Widths. For the most part, there is no need for code with listboxes, just use the property sheet. If you are new to MS Access it is often useful to use the wizards.
Upvotes: 2