【VB开源代码栏目提醒】:以下是网学会员为您推荐的VB开源代码-frmAddress.frm,希望本篇文章对您学习有所帮助。
VERSION 5.00
Begin VB.Form frmMain
BorderStyle = 1 'Fixed Single
Caption = "单记录浏览、编辑、查找"
ClientHeight = 3240
ClientLeft = 45
ClientTop = 330
ClientWidth = 6060
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3240
ScaleWidth = 6060
StartUpPosition = 3 '窗口缺省
Begin VB.Frame Frame3
Height = 2655
Left = 480
TabIndex = 12
Top = 240
Width = 1215
Begin VB.CommandButton cmdlast
Caption = "最后一条"
Height = 375
Left = 120
TabIndex = 16
Top = 2040
Width = 975
End
Begin VB.CommandButton cmdpre
Caption = "上一条"
Height = 375
Left = 120
TabIndex = 15
Top = 1440
Width = 975
End
Begin VB.CommandButton cmdnext
Caption = "下一条"
Height = 375
Left = 120
TabIndex = 14
Top = 840
Width = 975
End
Begin VB.CommandButton cmdfir
Caption = "第一条"
Height = 375
Left = 120
TabIndex = 13
Top = 240
Width = 975
End
End
Begin VB.Frame Frame1
Height = 735
Left = 2280
TabIndex = 4
Top = 2280
Width = 3135
Begin VB.CommandButton cmdSearch
Caption = "
搜索"
Height = 375
Left = 2040
TabIndex = 6
Top = 240
Width = 735
End
Begin VB.CommandButton cmdAdd
Caption = "添加"
Height = 375
Left = 360
TabIndex = 5
Top = 240
Width = 735
End
End
Begin VB.TextBox txtFax
Height = 285
Left = 3240
TabIndex = 3
Top = 1560
Width = 1935
End
Begin
VB.TextBox txtPhone
Height = 285
Left = 3240
TabIndex = 2
Top = 1200
Width = 1935
End
Begin VB.TextBox txtEmail
Height = 285
Left = 3240
TabIndex = 1
Top = 840
Width = 1935
End
Begin VB.TextBox txtName
Height = 285
Left = 3240
TabIndex = 0
Top = 480
Width = 1935
End
Begin VB.Frame Frame2
Caption = "数据库记录显示信息"
Height = 2055
Left = 2280
TabIndex = 7
Top = 120
Width = 3495
Begin VB.Label Label8
Caption = "传真:"
Height = 255
Left = 120
TabIndex = 11
Top = 1440
Width = 855
End
Begin VB.Label Label7
Caption = "电话:"
Height = 255
Left = 120
TabIndex = 10
Top = 1080
Width = 975
End
Begin VB.Label Label6
Caption = "Email:"
Height = 255
Left = 120
TabIndex = 9
Top = 720
Width = 975
End
Begin VB.Label Label5
Caption = ":"
Height = 375
Left = 120
TabIndex = 8
Top = 360
Width = 975
End
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim db As Database
Dim rs As Recordset
Private Sub cmdAdd_Click()
newName = InputBox("请输入:", "添加新记录对话框")
newEmail = InputBox("请输入Email地址:", "添加新记录对话框")
newPhone = InputBox("请输入电话号码:", "添加新记录对话框")
newFax = InputBox("请输入传真号码:", "添加新记录对话框")
With rs
.AddNew
!Name = LCase(newName)
!Email = LCase(newEmail)
!Phone = LCase(newPhone)
!Fax = LCase(newFax)
.Update
End With
MsgBox (newName & " 已添加到数据库表中!")
End Sub
Private Sub cmdfir_Click()
On Error Resume Next
rs.MoveFirst
txtName = rs.Fields("Name")
txtEmail = rs.Fields("Email")
txtPhone = rs.Fields("Phone")
txtFax = rs.Fields("Fax")
End Sub
Private Sub cmdlast_Click()
On Error Resume Next
rs.MoveLast
txtName = rs.Fields("Name")
txtEmail = rs.Fields("Email")
txtPhone = rs.Fields("Phone")
txtFax = rs.Fields("Fax")
End Sub
Private Sub cmdnext_Click()
On Error Resume Next
rs.MoveNext
txtName = rs.Fields("Name")
txtEmail = rs.Fields("Email")
txtPhone = rs.Fields("Phone")
txtFax = rs.Fields("Fax")
End Sub
Private Sub cmdpre_Click()
On Error Resume Next
rs.MovePrevious
txtName = rs.Fields("Name")
txtEmail = rs.Fields("Email")
txtPhone = rs.Fields("Phone")
txtFax = rs.Fields("Fax")
End Sub
Private Sub cmdSearch_Click()
Set rs = db.OpenRecordset("SELECT * FROM ppl")
NameQuery = InputBox("请输入:", "
查询对话框")
rs.MoveFirst
Do Until rs.EOF
If rs.Fields("name") Like "*" & LCase(NameQuery) & "*" Then
txtName = rs.Fields("Name")
txtEmail = rs.Fields("Email")
txtPhone = rs.Fields("Phone")
txtFax = rs.Fields("Fax")
Exit Sub
Else
rs.MoveNext
End If
Loop
End Sub
Private Sub Form_Load()
Set db = OpenDatabase(App.Path + "/vb2.mdb")
Set rs = db.OpenRecordset("ppl")
If rs.EOF Then
MsgBox "数据库表中没有信息"
Else
rs.MoveFirst
txtName = rs.Fields("Name")
txtEmail = rs.Fields("Email")
txtPhone = rs.Fields("Phone")
txtFax = rs.Fields("Fax")
End If
End Sub