ListBox table field names

  • Thread starter Thread starter Stu
  • Start date Start date
S

Stu

There must be a way to determine the field names of a ListBox whose record
source is Table/Query. For example I would like to know that
ME.LISTBOXNAME.COLUMN(0) corresponds to the field recordID in the table. How?
 
If the RowSource is strictly the tablename, change it to a query. You can
then open the query by clicking on the ellipsis (...) to the right of the
query name and run it, thus seeing the order in which the fields are
returned.

AFAIK, there's no property for a list box that will tell you that
information, since there are other ways of populating a list box for which
that property would be meaningless.
 
Yes, I know I can eyeball and count. I'm looking for a way to get the field
names if/when the table/query changes. The following code is the best I can
come up with. List0 is the listbox name, the event (click) is not relevant.
The index of the array will correspond to the field name.

Private Sub List0_Click()
Dim rst As DAO.Recordset
Dim fld As Field
Dim i As Integer
Dim a(20) As String
Set rst = Me.List0.Recordset

For i = 0 To rst.Fields.Count - 1
a(i) = rst.Fields(i).Name
Next i
rst.Close
End Sub
 
Back
Top