1

I'm developing a function to get the data from a query. I want to have both the field name (same from DB) and the field description before my data. I found how to get the field name but I did not find a way to get the description, can someone help me?

This is my current code to get the field name (and how I tried to get the description is commented):

'-Get the table's data
Set rs = con.Execute("SELECT * FROM " & Sh.name)

'-Set the name of the fields
Dim TheCells As range
Set TheCells = Sh.range("A2")
For i = 0 To rs.Fields.Count - 1
    TheCells.Offset(0, i).Value = rs.Fields(i).name
    'TheCells.Offset(1, i).Value = rs.Fields(i).Properties("Description").Value
Next i
Iohann Oro
  • 71
  • 1
  • 13

2 Answers2

1

You can use ADOX to get properties of columns.

Sub GetFieldDesc()

    Dim axCat As ADOX.Catalog
    Dim axTbl As ADOX.Table
    Dim adCon As ADODB.Connection
    Dim axProp As ADOX.Property

    'Create an ado connection
    Set adCon = New ADODB.Connection
    adCon.Open sCON

    'Point the adox catalog to that connection
    Set axCat = New ADOX.Catalog
    Set axCat.ActiveConnection = adCon

    'Pick your table
    Set axTbl = axCat.Tables("tblCurrentPriceDate")

    Debug.Print axTbl.Columns(0).Properties("Description").Value

End Sub

Set a reference to ActiveX Data Objects and to ADO Ext. x.x for DLL and Security

Dick Kusleika
  • 32,673
  • 4
  • 52
  • 73
0

I did not find any way to get the description from the recordset. What I found is a way to get the description from the properties in the database - basically running another query to get the description. How to write the query:

SQL Server

IBM

Community
  • 1
  • 1
Iohann Oro
  • 71
  • 1
  • 13