|
(一般)
Dim MyAccess As New Access.Application
Private Sub Command1_Click()
Dim MyNewTable As Object, MyNewField As Variant
MyAccess.NewCurrentDatabase "C:\通訊錄.mdb"
'產生新的mdb檔
Set MyNewTable = MyAccess.CurrentDb.CreateTableDef("好友通訊錄")
'透過Access的DBEngine產生新資料表
Set MyNewField = MyNewTable.CreateField("姓名", 10, 20)
'產生新的欄位
MyNewTable.Fields.Append MyNewField
'將欄位新增到資料表裡
Set MyNewField = MyNewTable.CreateField("電話", 10, 16)
MyNewTable.Fields.Append MyNewField
Set MyNewField = MyNewTable.CreateField("住址", 10, 16)
MyNewTable.Fields.Append MyNewField
MyAccess.CurrentDb.TableDefs.Append MyNewTable
Set MyAccess = Nothing
End Sub
●若是要在已存在的mdb檔加入新的資料表
(一般)
Dim MyAccess As New Access.Application
Private Sub Command1_Click()
Dim MyNewTable As Object, MyNewField As Variant
MyAccess.OpenCurrentDatabase "C:\通訊錄.mdb"
'產生新的mdb檔
Set MyNewTable = MyAccess.CurrentDb.CreateTableDef("壞友通訊錄")
Set MyNewField = MyNewTable.CreateField("姓名", 10, 20)
MyNewTable.Fields.Append MyNewField
Set MyNewField = MyNewTable.CreateField("電話", 10, 16)
MyNewTable.Fields.Append MyNewField
Set MyNewField = MyNewTable.CreateField("住址", 10, 16)
MyNewTable.Fields.Append MyNewField
MyAccess.CurrentDb.TableDefs.Append MyNewTable
Set MyAccess = Nothing
End Sub
●上面CreateField紅色底線處表示資料類型,而藍色底線則為資料長度
數值 資料類型 附註
1 布林數(是/否)
2 數字(Byte)
3 數字(Integer)
4 數字(Long)
5 貨幣
6 數字(Single)
7 數字(Double)
8 時間日期
9 Binary
10 字串
11 OLE物件
12 備忘
|
|