Access~テーブルのフィールド名を列挙する~

備忘録です。AccessのVBAでテーブルのフィールド名を取得する。

Dim pMyCN As New ADODB.Connection
Dim pMyRS As New ADODB.Recordset
Dim pLngCNT As Long
Dim pStrMyString As String

Set pMyCN = CurrentProject.Connection
pMyRS.Open "テーブル名", pMyCN, adOpenKeyset, adLockReadOnly

For pLngCNT = 0 To pMyRS.Fields.Count - 1
  If pLngCNT = 0 Then
  pStrMyString = pMyRS.Fields(pLngCNT).Name 
  Else
   pStrMyString = pStrMyString & "," & pMyRS.Fields(pLngCNT).Name 
  End If
Next pLngCNT
Debug.Print pStrMyString