How to List Field's Name in table in Access Using SQL

后端 未结 14 1284
我在风中等你
我在风中等你 2020-12-09 17:15

Can you please let me know if it is possible to list all fields name in a MS Access table?

14条回答
  •  轮回少年
    2020-12-09 17:44

    I work in ms access far too much.

    The only way I know of to do this, would be using vba, and defining for example a recordset, and looping through the fields.

    Eg:

    Sub ListFields()
    
    dim rst as new adodb.recordset
    rst.open "SELECT * FROM SomeTable", CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly
    ' Note: adOpenForwardOnly and adLockReadOnly are the default values '
    ' for the CursorType and LockType arguments, so they are optional here '
    ' and are shown only for completeness '
    
    dim ii as integer
    dim ss as string
    for ii = 0 to rst.fields.count - 1
        ss = ss & "," & rst.fields(ii).name
    next ii
    
    Debug.Print ss
    
    End Sub
    

    The string variable ss will contain a comma-delimited list of all the column names in the table named "SomeTable".

    With a little reformatting of the logic you should be able to insert this data into another table if you wanted to, then query it out.

    Does this help?

提交回复
热议问题