Using ADOX to find column names


Q: How can I find the column names in a table using ADO?

A. You will have to set a reference to the ADOX library (Microsoft ADO Ext. 2.1 for DDL and Security).

Let us presume that the variable strConnect contains a valid ConnectionString for your data. Then the following code should give you the intended result.

Private Sub Command1_Click()
  Dim catMine As New ADOX.Catalog
  Dim colAny As ADOX.Column

  catMine.ActiveConnection = strConnect

  For Each colAny In catMine.Tables("Customers").Columns
    Print colAny.Name
  Next colAny
End Sub