五、修改学籍窗体
1.修改日期控件
2.学号框、电话号码框限制。
3.为性别控件加入内容,为从班级表中加载班级信息,判断无记录情况。
Private Sub Form_Load()
comboSex.AddItem "男"
comboSex.AddItem "女"
Me.Height = 8500
Me.Width = 10000
Dim txtSQL As String
Dim MsgText As String
txtSQL = "select * from class_Info"
Set mrc = ExecuteSQL(txtSQL, MsgText)
'添加内容到列表框中
For i = 1 To mrc.RecordCount
comboClassno.AddItem mrc.Fields(0)
mrc.MoveNext
Next i
txtSQL = "select * from student_Info"
'执行查询操作
Set mrc = ExecuteSQL(txtSQL, MsgText) '得到临时表
If mrc.BOF Or mrc.EOF Then
x = MsgBox("无记录,是否先添加记录?", vbYesNo, "温馨提示")
If x = 6 Then
frmAddsinfo.Show
Unload Me
Else
Unload Me
End If
Else
mrc.MoveFirst
'显示数据
Call viewData
'记下当前记录的位置
myBookmark = mrc.Bookmark
'给标志赋初值
mcclean = True
End If
End Sub
4.性别、班号框不能被输入
Private Sub comboClassno_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub
Private Sub comboSex_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub
5.删除记录后无记录处理
Private Sub cmdDelete_Click()
'记下当前位置记录
myBookmark = mrc.Bookmark
'提示是否删除
Dim str2$
str2$ = MsgBox("是否删除当前记录?", vbOKCancel, "删除当前记录")
'判断按钮类型
If str2$ = vbOK Then
'移动到数据集一条记录
mrc.MoveNext
'判断数据集对象是否为空
If mrc.EOF Then
'移动到数据集的第一条记录
mrc.MoveFirst
'记录当前记录的位置
myBookmark = mrc.Bookmark
'移动到最后一条记录
mrc.MoveLast
'删除记录
mrc.Delete
mrc.Bookmark = myBookmark
'Call viewData
If mrc.EOF Or mrc.BOF Then
x = MsgBox("无记录,是否添加新的记录?", vbYesNo, "温馨提示")
If x = 6 Then
frmAddsinfo.Show
Unload Me
Else
Unload Me
End If
End If
Else
'记载当前位置
myBookmark = mrc.Bookmark
'移动到前一条记录
mrc.MovePrevious
'删除记录
mrc.Delete
'回到原来位置
mrc.Bookmark = myBookmark
'调用函数显示数据
'Call viewData
If mrc.EOF Or mrc.BOF Then
x = MsgBox("无记录,是否添加新的记录?", vbYesNo, "温馨提示")
If x = 6 Then
frmAddsinfo.Show
Unload Me
Else
Unload Me
End If
End If
End If
Else
mrc.Bookmark = myBookmark
Call viewData
End If
End Sub
六、查询学籍窗体
判断有无记录
Dim txtSQL As String
Dim MsgText As String
Dim mrc As ADODB.Recordset
'SQL语句
txtSQL = "select * from student_Info"
'执行查询操作
Set mrc = ExecuteSQL(txtSQL, MsgText) '得到临时表
If mrc.BOF Or mrc.EOF Then
x = MsgBox("无记录,是否先添加记录?", vbYesNo, "温馨提示")
If x = 6 Then
frmAddsinfo.Show
Unload Me
Else
Unload Me
Exit Sub
End If
End If
七、添加班级窗体
1.年级从表中获取
Private Sub Form_Load()
Me.Height = 5000
Me.Width = 8000
Dim mrc As ADODB.Recordset
Dim txtSQL As String
Dim MsgText As String
Dim i As Integer
txtSQL = "select * from gradecourse_Info"
Set mrc = ExecuteSQL(txtSQL, MsgText)
For i = 1 To mrc.RecordCount
comboGrade.AddItem mrc.Fields(0)
mrc.MoveNext
Next i
End Sub
2.年级框不能被编辑只能被选择
Private Sub comboGrade_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub
总结:优化是一个漫长的过程需要我们倾注耐心与细心,最重要的是我们要站在不同的角度看问题。