Get list of column names of specific table in VBA

VBA code shown below creates function that returns names of all columns of specific table.


Public Sub list_columns_in_table(table_name As String)

  Dim rst As New ADODB.Recordset
  rst.Open "select * from  " + table_name + " where 1=0", _

  For i = 0 To rst.Fields.Count - 1
    Debug.Print rst.Fields(i).Name
  Next i

End Sub


Execute funciton with following statement and provide your table name as parameter:

call  list_columns_in_table ("hr_employees")


The code builds query that returns no rows (where 1=0 condition), but it returns column names that are parsed in loop.


  • One row represents a column
  • Scope of rows: - all columns in specified table

Sample results

You can see all columns of hr employees table:

There are no comments. Click here to write the first comment.