前言:
而今同学们对“vb连接access数据库 密码”都比较关怀,看官们都需要学习一些“vb连接access数据库 密码”的相关内容。那么小编在网上收集了一些有关“vb连接access数据库 密码””的相关文章,希望我们能喜欢,你们快快来了解一下吧!模块
Public 成绩IDnum As Long
学生成绩管理
Private Sub Command更新_Click()
DoCmd.SetWarnings (False)
Dim update_sql As String
update_sql = "Update 学生成绩表 Set 考试日期=#" & 考试日期 & "#,姓名='" & 姓名 & "',科目='" & 科目 & "',分数=" & 分数 & " Where 成绩ID=" & 成绩ID
DoCmd.RunSQL update_sql
MsgBox "更新成功"
End Sub
Private Sub Command删除_Click()
If MsgBox("是否删除该记录", vbOKCancel) <> vbOK Then
Exit Sub
End If
DoCmd.SetWarnings (False)
Dim del_sql As String
del_sql = "Delete From 学生成绩表 Where 成绩ID= " & Me.成绩ID
DoCmd.RunSQL del_sql
MsgBox "删除成功"
DoCmd.Close acForm, Me.Name
End Sub
Private Sub Form_Close()
On Error Resume Next
Forms("学生成绩列表").Form.数据表子窗体.Requery
End Sub
Private Sub Form_Load()
Dim search_rs As DAO.Recordset
Dim search_sql As String
search_sql = "Select * From 学生成绩表 Where 成绩ID= " & 成绩IDnum
Set search_rs = CurrentDb.OpenRecordset(search_sql, dbOpenDynaset)
If search_rs.EOF = False Then
成绩ID.Value = search_rs!成绩ID.Value
考试日期.Value = search_rs!考试日期.Value
姓名.Value = search_rs!姓名.Value
科目.Value = search_rs!科目.Value
分数.Value = search_rs!分数.Value
End If
search_rs.Close
Set search_rs = Nothing
End Sub
学生成绩列表
Private Sub Command清除_Click()
考试日期.Value = ""
姓名.Value = ""
科目.Value = ""
分数.Value = ""
End Sub
Private Sub Command添加_Click()
On Error GoTo 添加失败错误
If 考试日期 = "" Or IsNull(考试日期) = True Then
MsgBox "考试日期值为空!"
Exit Sub
End If
If 姓名 = "" Or IsNull(姓名) = True Then
MsgBox "姓名值为空!"
Exit Sub
End If
If 科目 = "" Or IsNull(科目) = True Then
MsgBox "科目值为空!"
Exit Sub
End If
If 分数 = "" Or IsNull(分数) = True Then
MsgBox "分数值为空!"
Exit Sub
End If
Dim add_rs As DAO.Recordset
Set add_rs = CurrentDb.OpenRecordset("学生成绩表", dbOpenTable)
With add_rs
.AddNew
!考试日期.Value = 考试日期.Value
!姓名.Value = 姓名.Value
!科目.Value = 科目.Value
!分数.Value = 分数.Value
.Update
.Close
End With
Set add_rs = Nothing
MsgBox "添加成功!"
Me.数据表子窗体.Requery
Exit Sub
添加失败错误:
MsgBox Err.Description
End Sub
学生成绩数据表
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo 数据更新前提醒_Err
If (MsgBox("是否保存对记录的修改", 1, "修改记录提醒") = 1) Then
Else
DoCmd.RunCommand acCmdUndo
End If
数据更新前提醒_Exit:
Exit Sub
数据更新前提醒_Err:
MsgBox Error$
Resume 数据更新前提醒_Exit
End Sub
Private Sub 成绩ID_DblClick(Cancel As Integer)
成绩IDnum = Me.成绩ID
DoCmd.OpenForm "学生成绩管理", acNormal
End Sub