Reputation: 1686
I am pretty new to VBA . I have a table contains more than 30 fields. How do i store the column names into array using vba
My vba Code
Dim tdf As TableDef
Dim fld As Field
Dim o As Integer
Set tdf = db.TableDefs(tablename)
Dim n As Integer
n = tdf.Fields.Count
ReDim tablecolumns(0 To n) As String
For o = 0 To n
tablecolumns(n) = fld.Name(o)
Next o
Giving an error in this line
tablecolumns(n) = fld.Name(o)
Upvotes: 0
Views: 6075
Reputation: 6140
Ah, I'm modifying my answer to match your code.
Dim tdf As TableDef
Dim fld As Field
Dim o As Integer
Set tdf = db.TableDefs(tablename)
Dim n As Integer
n = tdf.Fields.Count
Dim tablecolumns() As String
ReDim tablecolumns(0 To n-1)
For o = 0 To n-1
tablecolumns(o) = tdf.Fields(o).Name
Next o
Upvotes: 1