📄 frm_employee.frm
字号:
MsgBox ("Please enter Password."), vbInformation, "Data missing"
ElseIf txt_pass2.Text = "" Then
MsgBox ("Please enter Password as Varifier so that wrong password can be detected."), vbInformation, "Data missing"
ElseIf txt_fname.Text = "" Then
MsgBox ("Please enter Employee first name."), vbInformation, "Data missing"
ElseIf txt_lname.Text = "" Then
MsgBox ("Please enter EmployeeID second name."), vbInformation, "Data missing"
ElseIf cmb_sex.Text = "" Then
MsgBox ("Please select the sex."), vbInformation, "Invalid arguments"
ElseIf (cmb_sex.Text <> "Male" And cmb_sex.Text <> "Female") Then
MsgBox ("Please select the sex."), vbInformation, "Invalid arguments"
ElseIf cmb_post.Text = "" Then
MsgBox ("Please select the post-aid."), vbInformation, "Invalid arguments"
ElseIf (cmb_post.Text <> "New" And cmb_post.Text <> "Temporary" And cmb_post.Text <> "Permanent") Then
MsgBox ("Please select the post-aid."), vbInformation, "Invalid arguments"
ElseIf txt_add.Text = "" Then
MsgBox ("Please enter Employee contact address."), vbInformation, "Data missing"
ElseIf txt_pass1.Text <> txt_pass2.Text Then
MsgBox ("May be typing mistake,Please re-enter the password."), vbInformation, "Invalid password"
txt_pass1.Text = ""
txt_pass2.Text = ""
txt_pass1.SetFocus
Else
flag = True
End If
cheak = flag
End Function
Private Sub showdata()
If Emprecordset.EOF = False And Emprecordset.BOF = False Then
txt_add.Text = Emprecordset.Fields(0)
txt_mail.Text = Emprecordset.Fields(1)
txt_empid.Text = Emprecordset.Fields(2)
txt_fname.Text = Emprecordset.Fields(3)
txt_lname.Text = Emprecordset.Fields(4)
txt_phone.Text = Emprecordset.Fields(5)
cmb_post.Text = Emprecordset.Fields(6)
txt_pass1.Text = Emprecordset.Fields(7)
txt_pass2.Text = Emprecordset.Fields(7)
txt_sal.Text = Emprecordset.Fields(8)
cmb_sex.Text = Emprecordset.Fields(9)
txt_note.Text = Emprecordset.Fields(10)
End If
End Sub
Private Sub clear()
txt_add.Text = ""
cmb_post.Text = ""
txt_mail.Text = ""
txt_empid.Text = ""
txt_fname.Text = ""
txt_lname.Text = ""
txt_note.Text = ""
txt_pass1.Text = ""
txt_pass2.Text = ""
txt_phone.Text = ""
txt_sal.Text = ""
cmb_sex.Text = ""
End Sub
Private Sub setlock(val As Boolean)
txt_add.Locked = val
cmb_post.Locked = val
txt_mail.Locked = val
txt_empid.Locked = val
txt_fname.Locked = val
txt_lname.Locked = val
txt_note.Locked = val
txt_pass1.Locked = val
txt_pass2.Locked = val
txt_phone.Locked = val
cmb_sex.Locked = val
End Sub
Private Sub button(val As Boolean)
cmd_new.Enabled = val
cmd_edit.Enabled = val
cmd_delete.Enabled = val
cmdFirst.Enabled = val
cmdLast.Enabled = val
cmdNext.Enabled = val
cmdPrevious.Enabled = val
cmd_save.Enabled = Not val
cmd_reset.Enabled = Not val
cmd_cancel.Enabled = Not val
End Sub
Private Sub cmb_post_Click()
If cmb_post.Text = "New" Then
txt_sal.Text = salnew
ElseIf cmb_post.Text = "Temporary" Then
txt_sal.Text = saltemp
Else
txt_sal.Text = salper
End If
End Sub
Private Sub cmd_cancel_Click()
On erro GoTo cancelerr
'disablink control
setlock (True)
lblStatus.Caption = " Cancel."
If Emprecordset.BOF And Emprecordset.EOF Then
GoTo newproc
Else
Emprecordset.MoveFirst
Call showdata
End If
newproc:
txt_fname.SetFocus
'enable control
cmdFirst.Enabled = True
cmdPrevious.Enabled = True
cmdNext.Enabled = True
cmdLast.Enabled = True
cmd_delete.Enabled = True
cmd_edit.Enabled = True
cmd_new.Enabled = True
'disable buttons
cmd_reset.Enabled = False
cmd_save.Enabled = False
cmd_cancel.Enabled = False
Exit Sub
cancelerr:
MsgBox Err.Description
End Sub
Private Sub cmd_close_Click()
Unload Me
End Sub
Private Sub Form_Load()
On Error GoTo errlable
If (view = 1) Then
Me.Top = 50
Me.Left = 50
ElseIf (view = 2) Then
Me.Top = 700
Me.Left = (Screen.Width - Me.Width) / 2
End If
Set Empconnection = New ADODB.Connection
Empconnection.CursorLocation = adUseClient
Empconnection.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & App.Path & "\Database\Library.mdb;Jet OLEDB:Database Password=Library;"
slct = "select Address,Email,Empid,Fname,Lname,Phone,Pos,Psword,Salary,Sex,Spe from Emptab Order by Fname"
Set Emprecordset = New ADODB.Recordset
Emprecordset.Open slct, Empconnection, adOpenStatic, adLockOptimistic
Call showdata
cmd_reset.Enabled = False
cmd_save.Enabled = False
cmd_cancel.Enabled = False
Exit Sub
errlable:
MsgBox Err.Number & Err.Description
End Sub
Private Sub cmd_delete_Click()
On Error GoTo delerr
Beep
If MsgBox("Execution of command will delete current Datarecord,Are you sure you wan't to delete Datarecord ?", vbYesNo + vbExclamation, "Confirm Delete") = vbYes Then
str = "DELETE FROM Emptab WHERE "
str = str & "Empid='"
str = str & Trim(txt_empid.Text) & "'"
'MsgBox str
Empconnection.Execute str
Emprecordset.Requery
MsgBox ("Record deleted Successfully."), vbInformation, "Delete"
If Emprecordset.BOF And Emprecordset.EOF Then
Call clear
MsgBox ("The previous record was last record,Now no record left."), vbInformation, "Last record"
cmd_delete.Enabled = False
Else
Emprecordset.MoveNext
If Emprecordset.EOF Then
Emprecordset.MoveLast
End If
Call showdata
End If
lblStatus.Caption = " Record deleted."
End If
Exit Sub
delerr:
MsgBox Err.Description
End Sub
Private Sub cmd_reset_Click()
Call clear
End Sub
Private Sub cmd_save_Click()
On erro GoTo saver
If cheak = True Then
'Autocorrection procedure
If cmb_post.Text = "New" Then
txt_sal.Text = salnew
ElseIf cmb_post.Text = "Temporary" Then
txt_sal.Text = saltemp
Else
txt_sal.Text = salper
End If
If txt_mail.Text = "" Then
txt_mail.Text = "None"
End If
If txt_phone.Text = "" Then
txt_phone.Text = "None"
End If
If txt_note.Text = "" Then
txt_note.Text = "None"
End If
pos = Emprecordset.AbsolutePosition
If saveflag = True Then
'for new record
str = "INSERT INTO Emptab "
str = str & "(Address,Email,Empid,Fname,Lname,Phone,Pos,Psword,Salary,Sex,Spe) "
str = str & "VALUES" & "('" & Trim(txt_add.Text) & "', "
str = str & "'" & Trim(txt_mail.Text) & "', "
str = str & "'" & Trim(txt_empid.Text) & "', "
str = str & "'" & Trim(txt_fname.Text) & "', "
str = str & "'" & Trim(txt_lname.Text) & "', "
str = str & "'" & Trim(txt_phone.Text) & "', "
str = str & "'" & Trim(cmb_post.Text) & "', "
str = str & "'" & Trim(txt_pass1.Text) & "', "
str = str & CDbl(txt_sal.Text) & ","
str = str & "'" & Trim(cmb_sex.Text) & "', "
str = str & "'" & Trim(txt_note.Text) & "')"
'MsgBox str
Empconnection.Execute str, , adCmdText + adExecuteNoRecords
Else
'for updating current record
str = "UPDATE Emptab SET "
str = str & "Address = '" & Trim(txt_add.Text) & "',"
str = str & " Pos = '" & Trim(cmb_post.Text) & "',"
str = str & " Email = '" & Trim(txt_mail.Text) & "',"
str = str & " Empid = '" & Trim(txt_empid.Text) & "',"
str = str & " Fname = '" & Trim(txt_fname.Text) & "',"
str = str & " Lname = '" & Trim(txt_lname.Text) & "',"
str = str & " Spe = '" & Trim(txt_note.Text) & "',"
str = str & " Psword = '" & Trim(txt_pass1.Text) & "',"
str = str & " Phone = '" & Trim(txt_phone.Text) & "',"
str = str & " Salary = " & CDbl(txt_sal.Text) & ","
str = str & " Sex = '" & Trim(cmb_sex.Text) & "'"
str = str & " WHERE Empid = '" & Trim(txt_empid.Text) & "'"
'MsgBox str
Empconnection.Execute str
End If
Emprecordset.Requery
Emprecordset.Move (pos - 1)
MsgBox ("Record saved successfully.")
lblStatus.Caption = " Record saved"
Call setlock(True)
Call button(True)
Call showdata
End If
Exit Sub
saver:
MsgBox Err.Description
End Sub
Private Sub cmdFirst_Click()
On Error GoTo GoFirstError
Emprecordset.MoveFirst
lblStatus.Caption = " << Move"
'show thw current data record
Call showdata
Exit Sub
GoFirstError:
MsgBox Err.Description
End Sub
Private Sub cmdLast_Click()
On Error GoTo GoLastError
lblStatus.Caption = " Move >>"
Emprecordset.MoveLast
'show thw current data record
Call showdata
Exit Sub
GoLastError:
MsgBox Err.Description
End Sub
Private Sub cmdNext_Click()
On Error GoTo GoNextError
lblStatus.Caption = " Move >"
If Not Emprecordset.EOF Then Emprecordset.MoveNext
If Emprecordset.EOF And Emprecordset.RecordCount > 0 Then
Beep
'moved off the end so go back
Emprecordset.MoveLast
End If
'show thw current data record
Call showdata
Exit Sub
GoNextError:
MsgBox Err.Description
End Sub
Private Sub cmdPrevious_Click()
On Error GoTo GoPrevError
lblStatus.Caption = " < Move"
If Not Emprecordset.BOF Then Emprecordset.MovePrevious
If Emprecordset.BOF And Emprecordset.RecordCount > 0 Then
Beep
'moved off the end so go back
Emprecordset.MovePrevious
End If
'show thw current data record
Call showdata
Exit Sub
GoPrevError:
If Err.Number = 3021 Then
MsgBox ("This is first Record."), vbInformation, "First record"
ElseIf Err.Number <> 0 Then
MsgBox Err.Number & Err.Description
End If
End Sub
Private Sub cmd_edit_Click()
On Error GoTo editerr
'Call clear
Call button(False)
Call setlock(False)
'cmd_cancel.Enabled = False
saveflag = False
lblStatus.Caption = " Edit record"
txt_empid.Locked = True
txt_fname.SetFocus
Exit Sub
editerr:
MsgBox Err.Description
End Sub
Private Sub cmd_new_Click()
On Error GoTo newerr
Call clear
Call button(False)
Call setlock(False)
saveflag = True
lblStatus.Caption = " Add new record."
txt_empid.SetFocus
Exit Sub
newerr:
MsgBox Err.Description
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -