📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "Comany Database"
ClientHeight = 5835
ClientLeft = 180
ClientTop = 255
ClientWidth = 7965
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 5835
ScaleWidth = 7965
StartUpPosition = 3 'Windows Default
Begin VB.Frame Frame4
Height = 975
Left = 120
TabIndex = 22
Top = 4560
Width = 7695
Begin VB.Label Label6
Caption = "http://zsoftwares.googlepages.com/VBprograms.htm"
BeginProperty Font
Name = "Verdana"
Size = 9.75
Charset = 0
Weight = 700
Underline = -1 'True
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000040C0&
Height = 495
Left = 120
TabIndex = 23
Top = 360
Width = 7335
End
End
Begin VB.Frame Frame1
Caption = "Employee"
Height = 4215
Left = 0
TabIndex = 0
Top = 0
Width = 7815
Begin VB.TextBox txtDob
Height = 375
Left = 2160
TabIndex = 16
Top = 2160
Width = 2895
End
Begin VB.Frame Frame2
Height = 3015
Left = 5280
TabIndex = 10
Top = 120
Width = 2415
Begin VB.CommandButton cmdSave
Caption = "SAVE"
Height = 495
Left = 120
TabIndex = 15
Top = 240
Visible = 0 'False
Width = 2175
End
Begin VB.CommandButton cmdSearch
Caption = "SEARCH"
Height = 495
Left = 120
TabIndex = 14
Top = 2400
Width = 2175
End
Begin VB.CommandButton cmdUpdate
Caption = "UPDATE"
Height = 495
Left = 120
TabIndex = 13
Top = 1680
Width = 2175
End
Begin VB.CommandButton cmdDelete
Caption = "DELETE"
Height = 495
Left = 120
TabIndex = 12
Top = 960
Width = 2175
End
Begin VB.CommandButton cmdAdd
Caption = "ADD"
Height = 495
Left = 120
TabIndex = 11
Top = 240
Width = 2175
End
End
Begin VB.Frame Frame3
Height = 855
Left = 240
TabIndex = 5
Top = 3240
Width = 7455
Begin VB.CommandButton cmdLast
Caption = "Move Last"
Height = 495
Left = 5520
TabIndex = 9
Top = 240
Width = 1815
End
Begin VB.CommandButton cmdPrevious
Caption = "Move Previous"
Height = 495
Left = 3720
TabIndex = 8
Top = 240
Width = 1815
End
Begin VB.CommandButton cmdNext
Caption = "Move Next"
Height = 495
Left = 1920
TabIndex = 7
Top = 240
Width = 1815
End
Begin VB.CommandButton cmdFirst
Caption = "Move First"
Height = 495
Left = 120
TabIndex = 6
Top = 240
Width = 1815
End
End
Begin VB.TextBox txtPhone
Height = 375
Left = 2160
TabIndex = 4
Top = 2760
Width = 2895
End
Begin VB.TextBox txtCity
Height = 375
Left = 2160
TabIndex = 3
Top = 1560
Width = 2895
End
Begin VB.TextBox txtName
Height = 375
Left = 2160
TabIndex = 2
Top = 960
Width = 2895
End
Begin VB.TextBox txtNo
Height = 375
Left = 2160
TabIndex = 1
Top = 360
Width = 2895
End
Begin VB.Label Label5
AutoSize = -1 'True
Caption = "Telephone Number :"
Height = 195
Left = 360
TabIndex = 21
Top = 2880
Width = 1455
End
Begin VB.Label Label4
AutoSize = -1 'True
Caption = "Date of Birth :"
Height = 195
Left = 360
TabIndex = 20
Top = 2280
Width = 975
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "City :"
Height = 195
Left = 360
TabIndex = 19
Top = 1680
Width = 345
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "Employee Name :"
Height = 195
Left = 360
TabIndex = 18
Top = 1080
Width = 1245
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Employee Number :"
Height = 195
Left = 360
TabIndex = 17
Top = 480
Width = 1380
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim adoconn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Declare Function ShellExecute Lib _
"shell32.dll" Alias "ShellExecuteA" _
(ByVal hWnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private SW_SHOWNORMAL
Private Sub cmdAdd_Click()
rs.AddNew
txtNo.Text = ""
txtName.Text = ""
txtCity.Text = ""
txtDob.Text = ""
txtPhone.Text = ""
cmdFirst.Enabled = False
cmdLast.Enabled = False
cmdNext.Enabled = False
cmdPrevious.Enabled = False
cmdDelete.Enabled = False
cmdSearch.Enabled = False
cmdUpdate.Enabled = False
cmdAdd.Visible = False
cmdSave.Visible = True
End Sub
Private Sub cmdDelete_Click()
Dim ans As String, str As String
ans = MsgBox("Do you really want to delete the current record?", vbExclamation + vbYesNo, "DELETE")
If ans = vbYes Then
adoconn.Execute ("delete from emp where e_no=" & txtNo.Text)
MsgBox ("The record has been deleted successfully.")
Set rs = Nothing
str = "select * from emp"
rs.Open str, adoconn, adOpenDynamic, adLockPessimistic
rs.MoveFirst
txtNo.Text = rs(0)
txtName.Text = rs(1)
txtCity.Text = rs(2)
txtDob.Text = rs(4)
txtPhone.Text = rs(3)
End If
End Sub
Private Sub cmdFirst_Click()
rs.MoveFirst
txtNo.Text = rs(0)
txtName.Text = rs(1)
txtCity.Text = rs(2)
txtDob.Text = rs(4)
txtPhone.Text = rs(3)
End Sub
Private Sub cmdLast_Click()
rs.MoveLast
txtNo.Text = rs(0)
txtName.Text = rs(1)
txtCity.Text = rs(2)
txtDob.Text = rs(4)
txtPhone.Text = rs(3)
End Sub
Private Sub cmdNext_Click()
rs.MoveNext
If rs.EOF = True Then
MsgBox "This is the last record.", vbExclamation, "Note it..."
rs.MoveLast
End If
txtNo.Text = rs(0)
txtName.Text = rs(1)
txtCity.Text = rs(2)
txtDob.Text = rs(4)
txtPhone.Text = rs(3)
End Sub
Private Sub cmdPrevious_Click()
rs.MovePrevious
If rs.BOF = True Then
MsgBox "This is the first record.", vbExclamation, "Note it..."
rs.MoveFirst
End If
txtNo.Text = rs(0)
txtName.Text = rs(1)
txtCity.Text = rs(2)
txtDob.Text = rs(4)
txtPhone.Text = rs(3)
End Sub
Private Sub cmdSave_Click()
rs(0) = txtNo.Text
rs(1) = txtName.Text
rs(2) = txtCity.Text
rs(4) = txtDob.Text
rs(3) = txtPhone.Text
rs.Update
MsgBox "The record has been saved successfully.", , "ADD"
cmdFirst.Enabled = True
cmdLast.Enabled = True
cmdNext.Enabled = True
cmdPrevious.Enabled = True
cmdDelete.Enabled = True
cmdSearch.Enabled = True
cmdUpdate.Enabled = True
cmdSave.Visible = False
cmdAdd.Visible = True
End Sub
Private Sub cmdSearch_Click()
Dim key As Integer, str As String
key = InputBox("Enter the Employee No whose details u want to know: ")
Set rs = Nothing
str = "select * from emp where e_no=" & key
rs.Open str, adoconn, adOpenForwardOnly, adLockReadOnly
txtNo.Text = rs(0)
txtName.Text = rs(1)
txtCity.Text = rs(2)
txtDob.Text = rs(4)
txtPhone.Text = rs(3)
Set rs = Nothing
str = "select * from emp"
rs.Open str, adoconn, adOpenDynamic, adLockPessimistic
End Sub
Private Sub cmdUpdate_Click()
Dim ans As String
ans = MsgBox("Do you really want to modify the current record?", vbExclamation + vbYesNo, "DELETE")
If ans = vbYes Then
rs.Update
cmdFirst.Enabled = False
cmdLast.Enabled = False
cmdNext.Enabled = False
cmdPrevious.Enabled = False
cmdDelete.Enabled = False
cmdSearch.Enabled = False
cmdUpdate.Enabled = False
cmdSave.Visible = True
cmdAdd.Visible = False
End If
End Sub
Private Sub Form_Load()
Dim str As String
Me.Caption = "Company Database"
Set adoconn = Nothing
adoconn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=employee.mdb;Persist Security Info=False"
str = "select * from emp"
rs.Open str, adoconn, adOpenDynamic, adLockPessimistic
rs.MoveFirst
txtNo.Text = rs(0)
txtName.Text = rs(1)
txtCity.Text = rs(2)
txtDob.Text = rs(4)
txtPhone.Text = rs(3)
End Sub
Private Sub Label6_Click()
ShellExecute Me.hWnd, _
vbNullString, _
"http://zsoftwares.googlepages.com/VBprograms.htm", _
vbNullString, _
"c:\", _
SW_SHOWNORMAL
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -