当前位置:Gxlcms > mysql > 用ADO建表ACCESS的表

用ADO建表ACCESS的表

时间:2021-07-01 10:21:17 帮助过:81人阅读

Option Explicit Dim FileName As String ' 创建数据库以及表和字段 Private Sub Command1_Click() Dim MyTable As TableDef Dim MyField As Field Dim MyDatabase As Database Set MyDatabase = CreateDatabase(FileName, dbLangGeneral) ' 创建数据库 Set M

Option Explicit

Dim FileName As String

' 创建数据库以及表和字段

Private Sub Command1_Click()

Dim MyTable As TableDef

Dim MyField As Field

Dim MyDatabase As Database

Set MyDatabase = CreateDatabase(FileName, dbLangGeneral) ' 创建数据库

Set MyTable = MyDatabase.CreateTableDef(Text2.Text) ' 创建表

Set MyField = MyTable.CreateField(Text3.Text, dbText, 50) ' 创建字段

MyTable.Fields.Append MyField ' 将新创建的字段添加到表中

MyDatabase.TableDefs.Append MyTable ' 将表添加到数据库中

' 重复创建多个表和字段并添加到数据库中

Set MyTable = MyDatabase.CreateTableDef(Text4.Text)

Set MyField = MyTable.CreateField(Text5.Text, dbText, 50)

MyTable.Fields.Append MyField

Set MyField = MyTable.CreateField(Text6.Text, dbText, 50)

MyTable.Fields.Append MyField

MyDatabase.TableDefs.Append MyTable

MsgBox "完成创建数据库 " + FileName

End Sub

' 设置创建的数据库的位置和名称

Private Sub Command2_Click()

' 设置对话框

With CommonDialog1

.CancelError = True

.Filter = "数据库(*.mdb)|*.mdb"

.Flags = cdlOFNHideReadOnly

.ShowSave

If Err.Number = cdlCancel Then

Err.Clear

Exit Sub

End If

FileName = .FileName

Text1.Text = .FileTitle

End With

End Sub

' 退出程序

Private Sub Command3_Click()

End

End Sub

人气教程排行