HOW TO

Access field names in a Recordset when you do not know the field names

Last Published: April 25, 2020

Summary

There are two techniques to access the list of all field names from a Recordset. The first returns all the fields in the Fields Collection. The second approach uses the TableDesc object. The order of the fields will be more accurate when using the TableDesc object method.

Procedure



To access the fields in a Recordset without knowing the names you can populate a List Box using the following code in Visual Basic:


Code:
Dim fld As MapObjects2.Field
For Each fld In Map1.Layers(0).Records.Fields
List1.AddItem fld.name
Next fld

However, this list is not necessarily returned in the same order as found in the .DBF file. In order to return the field names in the same order as found in the .DBF file, you can access the Field names by index number using the TableDesc object using the following code:


Code:
Dim tDesc1 As MapObjects2.TableDesc
Set tDesc1 = Map1.Layers(0).Records.TableDesc
Dim iFieldCount As Integer
iFieldCount = tDesc1.FieldCount
Dim i As Integer

Do Until i = iFieldCount
List2.AddItem tDesc1.FieldName(i)
i = i + 1
Loop

Article ID:000002591

Software:
  • Legacy Products

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic