itguyme
itguyme

Reputation: 43

Listbox show column names of table

I'm trying to get a listbox to show a list of all columns (fields) that are available in a particular table. Now the following code below achieves this but uses a msgbox to display each field which I dont want.

Dim rst As DAO.Recordset
Dim fld As DAO.Field
Set rst = CurrentDb.OpenRecordset("YourTableName")
For Each fld In rst.Fields
    MsgBox fld.Name
Next fld
rst.Close
Set rst = Nothing
Set fld = Nothing

Basically I want a combo or a listbox to show all fields from a particular table - is this possible?

Upvotes: 1

Views: 953

Answers (1)

Gustav
Gustav

Reputation: 55816

You are making it way too hard for yourself.

In the property pane of the listbox, set:

RowSource:     YourTableName
RowSourceType: Field List

Upvotes: 3

Related Questions