PrivateSubCommand1_Click()
OnErrorGoToErr100
'定義表與字段
DimDefDatabaseAsDatabase
DimDefTableAsTableDef,DefFieldAsField
SetDefDatabase=Workspaces(0).OpenDatabase(App.Path&"vbeden.mdb",0,False)
SetDefTable=DefDatabase.CreateTableDef("VB編程樂園")
'dbBinary=9
'dbBoolean=1
'dbByte=2
'dbChar=18
'dbDate=8
'dbInteger=3
'dbLong=4
'dbMemo=12
'dbText=10
'建立Name字段為8個字符型
SetDefField=DefTable.CreateField("Name",dbText,8)
DefTable.Fields.AppendDefField
SetDefField=DefTable.CreateField("Sex",dbText,2)
DefTable.Fields.AppendDefField
'該字段允許為空
DefField.AllowZeroLength=True
'建立Age字段為3個的常整型
SetDefField=DefTable.CreateField("Age",dbInteger,3)
'字段追加
DefTable.Fields.AppendDefField
'表追加
DefDatabase.TableDefs.AppendDefTable
MsgBox"VB編程樂園數據庫建立完成!",vbInformation
ExitSub
Err100:
MsgBox"對不起,不能建立表。請先再建表前建立VBEden數據庫?",vbCritical
EndSub
PrivateSubcmdCreate_Click()
OnErrorGoToErr100
'建立名為VBEDEN的數據庫
CreateDatabase"VB-CODE",dbLangGeneral
MsgBox"數據庫建立完成!",vbInformation
ExitSub
Err100:
MsgBox"不能建立數據庫!"&vbCrLf&vbCrLf&Err.Description,vbInformation
EndSub->