Access list tables
VBA で MS-Access のテーブル一覧およびカラム一覧を取得する
Sub GetTableFieldName()
Dim MyDB As Database
Dim strTbl As String
Dim i As Integer
'オブジェクト変数の設定
Set MyDB = DBEngine.Workspaces(0).OpenDatabase("C:\data.mdb")
For i = 1 To MyDB.TableDefs.Count
strTbl = MyDB.TableDefs(i - 1).Name
'取得した TableDef オブジェクトが [MSys/USys] 以外ではじまるの名前
If Left$(strTbl, 4) <> "MSys" And Left$(strTbl, 4) <> "USys" Then
' Debug.Print strTbl
Set MyTBL = MyDB.TableDefs(strTbl)
Debug.Print "[" & strTbl & "]"
Dim strFldAll As String
strFldAll = ""
'フィールド名を取得
For j = 1 To MyTBL.Fields.Count
strFld = MyTBL.Fields(j - 1).Name
' Debug.Print strFld
If j <> 1 Then
strFldAll = strFldAll & "," & strFld
Else
strFldAll = strFld
End If
Next
Debug.Print strFldAll
End If
Next
End Sub
tags
---
vba access mdb テーブル名 カラム名
vba access mdb tables columns