The recordset from adSchemaColumns
gives you COLUMN_NAME
and ORDINAL_POSITION
fields. So you can load those field values into a Scripting.Dictionary
and later walk the dictionary in ORDINAL_POSITION
order and .Echo COLUMN_NAME
.
Here is a VBScript example for the columns in one table.
Option Explicit
Public Const adSchemaColumns = 4
Dim cn, rs, dct, i
Set dct = CreateObject("Scripting.Dictionary")
Set cn = CreateObject("ADODB.Connection")
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source='C:\share\Access\database1.mdb'"
Set rs = cn.OpenSchema(adSchemaColumns, _
Array(Null, Null, "tblFoo"))
With rs
Do While Not .EOF
dct.Add .Fields("ORDINAL_POSITION").Value, _
.Fields("COLUMN_NAME").Value
.MoveNext
Loop
.Close
End With
For i = 1 To dct.Count
WScript.Echo dct(i)
Next
Set dct = Nothing
Set rs = Nothing
cn.Close
Set cn = Nothing