| 導購 | 订阅 | 在线投稿
分享
 
 
 

用ADO建表ACCESS的表

來源:互聯網  2008-05-18 23:55:16  評論

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

  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
󰈣󰈤
王朝萬家燈火計劃
期待原創作者加盟
 
 
 
>>返回首頁<<
 
 
 
 
 熱帖排行
 
 
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有