|
参考までに、私が使った DAO のテーブル作成マクロをUPしておきます。
株価データを格納するテーブルを作りました。
Sub MyDBテーブル作成()
Dim wspDefault As Workspace
Dim myCurDb As Database
Dim myTblDef As TableDef
Dim myNewIdx As Index
Dim fld As Field
Dim C As Range
Dim i As Integer
Dim TName As String
Const myMdbFile = "C:\My Documents\NewYork_data.mdb"
Set wspDefault = DBEngine.Workspaces(0)
Set myCurDb = wspDefault.OpenDatabase(myMdbFile)
MyAr = Array("始値", "高値", "安値", "終値", "出来高")
For Each C In Sheets("Sheet1").Range("A1:A33")
TName = C.Value & "_" & C.Offset(, 1).Value
Set myTblDef = myCurDb.CreateTableDef(TName)
With myTblDef
Set fld = .CreateField("日付", dbDate, 8)
.Fields.Append fld
fld.OrdinalPosition = 0
Set myNewIdx = .CreateIndex("MyIdx")
With myNewIdx
.Fields.Append .CreateField("日付")
.Primary = True
End With
.Indexes.Append myNewIdx
For i = LBound(MyAr) To UBound(MyAr)
Set fld = .CreateField(MyAr(i), dbLong)
.Fields.Append fld
fld.OrdinalPosition = i + 1
Set fld = Nothing
.Fields.Refresh
Next i
End With
myCurDb.TableDefs.Append myTblDef
Set myTblDef = Nothing
Next
myCurDb.Close: wspDefault.Close
Set myCurDb = Nothing: Set wspDefault = Nothing
End Sub
|
|