Private Sub Cmdsave_Click() ’保存按钮命令
If txtstudentName.Text = Empty Then ’ 设置各种输入为空出错提示
MsgBox "请输入姓名!", vbInformation, "提示"
txtstudentName.SetFocus
Exit Sub
End If
If cboClass.Text = Empty Then
MsgBox "请选择部门!", vbInformation, "提示"
cboClass.SetFocus
Exit Sub
End If
If cboSex.Text = Empty Then
MsgBox "请选择性别!", vbInformation, "提示"
cboSex.SetFocus
Exit Sub
End If
If txtStudentId.Text = Empty Then
MsgBox "请输入员工号!", vbInformation, "提示"
txtStudentId.SetFocus
Exit Sub
End If
If txtBirth.Text = Empty Then
MsgBox "请输入出生日期!", vbInformation, "提示"
txtBirth.SetFocus
Exit Sub
ElseIf Not IsDate(txtBirth) Then ’设置各种非有效值出错
MsgBox "出生日期不是有效日期,请重新输入.", vbInformation, "提示"
txtBirth.SetFocus
txtBirth.Text = "____-__-__"
Exit Sub
ElseIf Format(txtBirth.Text, "yyyy/mm/dd") > Format(Date, "yyyy/mm/dd") Then
MsgBox "出生日期不能大于今日,请重新输入!", vbInformation, "提示"
txtBirth.SetFocus
Exit Sub
ElseIf Format(txtBirth.Text, "yyyy/mm/dd") < Format(#1/1/1900#, "yyyy/mm/dd") Then
MsgBox "生出日期不能小于1900年,请重新输入!", vbInformation, "提示"
txtBirth.SetFocus
txtBirth.Text = "____-__-__"
Exit Sub
End If
If txtInDate.Text = Empty Then
MsgBox "请输入就职时间!", vbInformation, "提示"
txtInDate.SetFocus
Exit Sub
End If
If Not IsDate(txtInDate) Then
MsgBox "就职时间不是有效日期,请重新输入!", vbInformation, "提示"
txtInDate.SetFocus
txtInDate.Text = "____-__-__"
Exit Sub
ElseIf Format(txtBirth.Text, "yyyy/mm/dd") > Format(Date, "yyyy/mm/dd") Then
MsgBox "就职日期不能大于今日,请重新输入!", vbInformation, "提示"
txtInDate.SetFocus
txtInDate.Text = "____-__-__"
Exit Sub
ElseIf Format(txtInDate.Text, "yyyy/mm/dd") < Format(#1/1/1900#, "yyyy/mm/dd") Then
MsgBox "就职日期不能小于1900年,请重新输入!", vbInformation, "提示"
txtInDate.SetFocus
txtInDate.Text = "____-__-__"
Exit Sub
End If
If txtTel.Text = Empty Then
If MsgBox("联系电话是否为空?", vbYesNo + vbQuestion, "提示") = vbNo Then
txtTel.SetFocus
Exit Sub
Else
txtTel.Text = "无"
End If
End If
If txtAdd.Text = Empty Then
MsgBox "请输入家庭地址!", vbInformation, "提示"
txtAdd.SetFocus
Exit Sub
End If
If txtcomment.Text = Empty Then
txtcomment.Text = "无"
End If
If cmdSave.Caption = "保存(&S)" Then
myModiStudent.rsDK1 "select * from student_Info where student_id='" & txtStudentId.Text & "'"
If Not myModiStudent.rs1.EOF Then
MsgBox "id已存在,请重新输入!", vbOKOnly + vbInformation, "提示"
txtStudentId.Text = ""
Exit Sub
End If
With myModiStudent.rs1 ’添加指向表的数据集
.AddNew
!student_id = txtStudentId.Text ’输入信息存入数据集
!student_name = txtstudentName.Text
!student_sex = cboSex.Text
!Birth_date = txtBirth.Text
!depart = cboClass.Text
!tele_number = txtTel.Text
!in_date = txtInDate.Text
!address = txtAdd.Text
!comment = txtcomment.Text
.Update ’更新保存
End With
Set StudentGrid.DataSource = myModiStudent.rs1 ’设置指向数据源的数据集
StudentGrid.FormatString = " | 编号| 姓名|性别| 出生日期 |部门| 联系电话| 就职时间| 家庭住址 | 注释"
MsgBox "信息已成功添加!", vbOKOnly + vbInformation, "员工信息添加"
Frame2.Enabled = False
cmdAdd.Caption = "添加(&A)"
cmdSave.Caption = "保存(&S)"
cmdSave.Enabled = False
cmdDel.Enabled = False
Else
myModiStudent.rsDK1 "select * from student_info where student_id='" & txtStudentId.Text & "'"
With myModiStudent.rs1
!student_id = txtStudentId.Text
!student_name = txtstudentName.Text
!student_sex = cboSex.Text
!Birth_date = txtBirth.Text
!depart = cboClass.Text
!tele_number = txtTel.Text
!in_date = txtInDate.Text
!address = txtAdd.Text
!comment = txtcomment.Text
.Update ’成功保存数据
End With
MsgBox "信息已成功更新!", vbOKOnly + vbInformation, "员工信息添加"
Frame2.Enabled = False
cmdSave.Caption = "保存(&S)"
cmdAdd.Caption = "添加(&A)"
cmdSave.Enabled = False
cmdDel.Enabled = False
End If
StudentGrid.FormatString = " | 编号| 姓名|性别| 出生日期 |部门| 联系电话| 就职时间| 家庭住址 | 注释"
myModiStudent.rsDK1 "SELECT * FROM student_info"
Set StudentGrid.DataSource = myModiStudent.rs1
End Sub
Private Sub StudentGrid_Click() ’点击列表框的任何数据时将其导出输入控件
myModiStudent.rsDK1 "SELECT * FROM student_info"
If Not myModiStudent.rs1.EOF Then
Frame2.Enabled = True
Change = False
txtstudentName.Text = StudentGrid.TextMatrix(StudentGrid.Row, 2)
cboClass.Text = StudentGrid.TextMatrix(StudentGrid.Row, 5)
txtStudentId.Text = StudentGrid.TextMatrix(StudentGrid.Row, 1)
cboSex.Text = StudentGrid.TextMatrix(StudentGrid.Row, 3)
txtBirth.Text = Format(StudentGrid.TextMatrix(StudentGrid.Row, 4), "yyyy-mm-dd")
txtTel.Text = StudentGrid.TextMatrix(StudentGrid.Row, 6)
txtInDate.Text = Format(StudentGrid.TextMatrix(StudentGrid.Row, 7), "yyyy-mm-dd")
txtAdd.Text = StudentGrid.TextMatrix(StudentGrid.Row, 8)
txtcomment.Text = StudentGrid.TextMatrix(StudentGrid.Row, 9)
cmdSave.Caption = "更新(&U)"
cmdAdd.Caption = "添加(&A)"
cmdDel.Enabled = True
cmdSave.Enabled = True
End If
End sub
EnPrivate Sub txtAdd_KeyPress(KeyAscii As Integer) ’回车激发添加按钮
If KeyAscii = 39 Then KeyAscii = 0
If KeyAscii = 13 Then txtcomment.SetFocus
End Sub
Private Sub txtBirth_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then txtTel.SetFocus
End Sub
Private Sub txtBirth_LostFocus()
txtBirth.Text = Format(txtBirth.Text, "yyyy/mm/dd")
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>