📄 data.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "电话簿"
ClientHeight = 1890
ClientLeft = 60
ClientTop = 345
ClientWidth = 4215
LinkTopic = "Form1"
ScaleHeight = 1890
ScaleWidth = 4215
StartUpPosition = 3 '窗口缺省
Begin VB.Data Data1
Caption = "Data1"
Connect = "Access 2000;"
DatabaseName = "data.mdb"
DefaultCursorType= 0 '缺省游标
DefaultType = 2 '使用 ODBC
Exclusive = 0 'False
Height = 375
Left = 360
Options = 0
ReadOnly = 0 'False
RecordsetType = 1 'Dynaset
RecordSource = "电话簿"
Top = 0
Width = 1935
End
Begin VB.TextBox name1
DataField = "姓名"
DataSource = "Data1"
Height = 270
Left = 1080
TabIndex = 8
Text = "Text1"
Top = 120
Width = 2055
End
Begin VB.CommandButton ComAdd
Caption = "添 加"
Height = 255
Left = 2160
TabIndex = 7
Top = 1080
Width = 975
End
Begin VB.CommandButton ComDel
Caption = "删 除"
Height = 255
Left = 3240
TabIndex = 6
Top = 1080
Width = 975
End
Begin VB.CommandButton ComFind
Caption = "查 询"
Height = 255
Left = 2760
TabIndex = 5
Top = 1440
Width = 975
End
Begin VB.ComboBox CobFind
Height = 300
ItemData = "Data.frx":0000
Left = 600
List = "Data.frx":0002
Style = 2 'Dropdown List
TabIndex = 4
Top = 1440
Width = 975
End
Begin VB.TextBox TexFind
Height = 270
Left = 1680
TabIndex = 3
Top = 1440
Width = 975
End
Begin VB.CommandButton comprev
Caption = "上一条"
Height = 255
Left = 0
TabIndex = 2
Top = 1080
Width = 975
End
Begin VB.CommandButton comnext
Caption = "下一条"
Height = 255
Left = 1080
TabIndex = 1
Top = 1080
Width = 975
End
Begin VB.TextBox tel
DataField = "电话"
DataSource = "Data1"
Height = 270
Left = 1080
TabIndex = 0
Text = "Text3"
Top = 600
Width = 2055
End
Begin VB.Label Label1
BackColor = &H00808000&
BackStyle = 0 'Transparent
Caption = "姓名"
BeginProperty Font
Name = "隶书"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 360
TabIndex = 10
Top = 180
Width = 615
End
Begin VB.Label Label3
BackColor = &H00808000&
BackStyle = 0 'Transparent
Caption = "电话"
BeginProperty Font
Name = "隶书"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 360
TabIndex = 9
Top = 660
Width = 615
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_Load()
Data1.Visible = False
' 添加查询选项
CobFind.AddItem "姓名"
CobFind.AddItem "电话"
End Sub
' 添加记录
Private Sub ComAdd_Click()
If ComAdd.Caption = "确 定" Then
On Error GoTo errorhandler
' 更新记录集
Data1.UpdateRecord
' 移动到最后一条记录
Data1.Recordset.MoveLast
comprev.Enabled = True
comnext.Enabled = True
ComDel.Enabled = True
ComFind.Enabled = True
ComAdd.Caption = "添 加"
Else
' 添加新的记录
Data1.Recordset.AddNew
ComAdd.Caption = "确 定"
comprev.Enabled = False
comnext.Enabled = False
ComDel.Enabled = False
ComFind.Enabled = False
End If
Exit Sub
'错误处理
errorhandler:
If Err.Number = 524 Then
MsgBox "该记录已存在!", 48, "警告" '输入的姓名相同
End If
Resume
End Sub
'删除记录
Private Sub ComDel_Click()
Dim i As Integer
i = MsgBox("真的要删除当前记录吗?", vbYesNo, "警告")
If i = 6 Then
'删除记录
Data1.Recordset.Delete
Data1.Refresh
End If
End Sub
' 上一条
Private Sub comprev_Click()
Data1.Recordset.MovePrevious
comnext.Enabled = True
If Data1.Recordset.BOF Then
Data1.Recordset.MoveFirst
comprev.Enabled = False
End If
End Sub
' 下一条
Private Sub comnext_Click()
Data1.Recordset.MoveNext
comprev.Enabled = True
If Data1.Recordset.EOF Then
Data1.Recordset.MoveLast
comnext.Enabled = False
End If
End Sub
' 查询
Private Sub ComFind_Click()
If TexFind.Text = "" Then
MsgBox "请选择查询项目并输入查询内容!", 48, "提示"
Exit Sub
End If
' 进行根据选择条件查询
Data1.Recordset.FindFirst CobFind.Text & "=" & "'" & TexFind.Text & "'"
' 如果没有找到记录
If Data1.Recordset.NoMatch Then
MsgBox "记录不存在", 64, "提示"
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -