简体   繁体   中英

How to store table column names into array using access vba

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM