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->
……