任务日程管理系统-VBA代码
任务日期查询数据表
任务日程管理
Private Sub Command保存_Click()
If MsgBox("是否保存对记录的修改", vbOKCancel) <> vbOK Then
Exit Sub
End If
If Me.任务ID <> "" Then
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
If 是否完成 = "" Or IsNull(是否完成) = True Then
MsgBox "是否完成值为空!"
Exit Sub
End If
Dim search_rs As DAO.Recordset
Dim search_sql As String
search_sql = "Select * From 任务日程表 Where 任务ID=" & Me.任务ID
Set search_rs = CurrentDb.OpenRecordset(search_sql, dbOpenDynaset)
If search_rs.EOF = False Then
search_rs.Edit
search_rs!日期.Value = 日期.Value
search_rs!时间段.Value = 时间段.Value
search_rs!标题.Value = 标题.Value
search_rs!内容.Value = 内容.Value
search_rs!标签.Value = 标签.Value
search_rs!类别.Value = 类别.Value
search_rs!重要程度.Value = 重要程度.Value
search_rs!是否完成.Value = 是否完成.Value
search_rs.Update
End If
search_rs.Close
Set search_rs = Nothing
MsgBox "保存完成"
Me.数据表子窗体.Requery
Else
MsgBox "请选择任务ID"
Exit Sub
End If
End Sub
Private Sub Command查询_Click()
Me.任务ID = ""
Dim filter_text As String
If 日期 <> "" Then
If filter_text <> "" Then
filter_text = filter_text & " and " & "日期>#" & Me.日期 & "#"
Else
filter_text = "日期>#" & Me.日期 & "#"
End If
End If
If 时间段 <> "" Then
If filter_text <> "" Then
filter_text = filter_text & " and " & "时间段 like '*" & Me.时间段 & "*'"
Else
filter_text = "时间段 like '*" & Me.时间段 & "*'"
End If
End If
If 标题 <> "" Then
If filter_text <> "" Then
filter_text = filter_text & " and " & "标题 like '*" & Me.标题 & "*'"
Else
filter_text = "标题 like '*" & Me.标题 & "*'"
End If
End If
If 内容 <> "" Then
If filter_text <> "" Then
filter_text = filter_text & " and " & "内容 like '*" & Me.内容 & "*'"
Else
filter_text = "内容 like '*" & Me.内容 & "*'"
End If
End If
If 标签 <> "" Then
If filter_text <> "" Then
filter_text = filter_text & " and " & "标签 like '*" & Me.标签 & "*'"
Else
filter_text = "标签 like '*" & Me.标签 & "*'"
End If
End If
If 类别 <> "" Then
If filter_text <> "" Then
filter_text = filter_text & " and " & "类别 like '*" & Me.类别 & "*'"
Else
filter_text = "类别 like '*" & Me.类别 & "*'"
End If
End If
If 重要程度 <> "" Then
If filter_text <> "" Then
filter_text = filter_text & " and " & "重要程度 like '*" & Me.重要程度 & "*'"
Else
filter_text = "重要程度 like '*" & Me.重要程度 & "*'"
End If
End If
If 是否完成 <> "" Then
If filter_text <> "" Then
filter_text = filter_text & " and " & "是否完成 =" & Me.是否完成
Else
filter_text = "是否完成 =" & Me.是否完成
End If
End If
If filter_text <> "" Then
Me.数据表子窗体.Form.Filter = filter_text
Me.数据表子窗体.Form.FilterOn = True
Else
Me.数据表子窗体.Form.FilterOn = False
End If
End Sub
Private Sub Command清空_Click()
任务ID.Value = ""
日期.Value = ""
时间段.Value = ""
标题.Value = ""
内容.Value = ""
标签.Value = ""
类别.Value = ""
重要程度.Value = ""
Me.是否完成 = False
End Sub
Private Sub Command全部_Click()
Me.任务ID = ""
Me.数据表子窗体.Form.FilterOn = False
End Sub
Private Sub Command删除_Click()
If MsgBox("是否删除该记录", vbOKCancel) <> vbOK Then
Exit Sub
End If
If Me.任务ID <> "" Then
DoCmd.SetWarnings (False)
Dim del_sql As String
del_sql = "Delete From 任务日程表 Where 任务ID=" & Me.任务ID
DoCmd.RunSQL del_sql
MsgBox "删除完成"
Call Command清空_Click
Me.数据表子窗体.Requery
Else
MsgBox "请选择任务ID"
Exit Sub
End If
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
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
!标签.Value = 标签.Value
!类别.Value = 类别.Value
!重要程度.Value = 重要程度.Value
!是否完成.Value = 是否完成.Value
.Update
.Close
End With
Set add_rs = Nothing
MsgBox "添加成功!"
Me.数据表子窗体.Requery
Me.任务ID = ""
Exit Sub
添加失败错误:
MsgBox "添加失败!"
End Sub
Private Sub Form_Load()
Me.是否完成 = False
End Sub