Matt
Matt

Reputation: 4117

Get column names

I need to get all of the column names of a table using VBA or Access SQL and iterate through them for validation, does anyone have a solution to this, I have searched Google to no avail.

Upvotes: 15

Views: 53863

Answers (2)

Jose
Jose

Reputation: 119

Dim l As Integer

For l = 0 To CurrentDb.TableDefs("tbl_Name").Fields.Count - 1
  Debug.Print CurrentDb.TableDefs("tbl_Name").Fields(l).name
Next l

Upvotes: 11

Fergal Moran
Fergal Moran

Reputation: 4634

This will work

Set db = CurrentDb()
Set rs1 = db.OpenRecordset("Table1")
Dim fld As DAO.Field
For Each fld In rs1.Fields
    MsgBox (fld.Name)
Next
Set fld = Nothing

Upvotes: 19

Related Questions