📄 form1.frm
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form Form1
Caption = "创建数据库"
ClientHeight = 3435
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form2"
ScaleHeight = 3435
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command3
Caption = "退出"
Height = 375
Left = 2640
TabIndex = 11
Top = 2760
Width = 1455
End
Begin VB.CommandButton Command2
Caption = "..."
Height = 375
Left = 2040
TabIndex = 10
Top = 120
Width = 615
End
Begin MSComDlg.CommonDialog CommonDialog1
Left = 240
Top = 2880
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.TextBox Text6
Height = 390
Left = 3600
TabIndex = 6
Text = "字段2"
Top = 1920
Width = 855
End
Begin VB.TextBox Text5
Height = 375
Left = 2640
TabIndex = 5
Text = "字段1"
Top = 1920
Width = 855
End
Begin VB.TextBox Text4
Height = 375
Left = 3000
TabIndex = 4
Text = "表2"
Top = 960
Width = 1095
End
Begin VB.TextBox Text3
Height = 375
Left = 840
TabIndex = 3
Text = "字段1"
Top = 1920
Width = 1095
End
Begin VB.TextBox Text2
Height = 375
Left = 840
TabIndex = 2
Text = "表1"
Top = 960
Width = 1095
End
Begin VB.CommandButton Command1
Caption = "创建"
Height = 375
Left = 720
TabIndex = 1
Top = 2760
Width = 1455
End
Begin VB.TextBox Text1
ForeColor = &H8000000F&
Height = 375
Left = 3120
Locked = -1 'True
TabIndex = 0
Text = "文件名"
Top = 120
Width = 1215
End
Begin VB.Label Label3
Caption = "字段:"
Height = 375
Left = 120
TabIndex = 9
Top = 1920
Width = 495
End
Begin VB.Label Label2
Caption = "表:"
Height = 255
Left = 240
TabIndex = 8
Top = 1080
Width = 255
End
Begin VB.Label Label1
Caption = "数据库位置:"
Height = 255
Left = 360
TabIndex = 7
Top = 240
Width = 1815
End
Begin VB.Shape Shape2
Height = 1695
Left = 2520
Top = 840
Width = 2055
End
Begin VB.Shape Shape1
Height = 1695
Left = 720
Top = 840
Width = 1575
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -