任務(wù)日程管理系統(tǒng)-VBA代碼
任務(wù)日期查詢數(shù)據(jù)表
任務(wù)日程管理
Private Sub Command保存_Click()
If MsgBox("是否保存對(duì)記錄的修改", vbOKCancel) <> vbOK Then
Exit Sub
End If
If Me.任務(wù)ID <> "" Then
? ? If 日期 = "" Or IsNull(日期) = True Then
? ? MsgBox "日期值為空!"
? ? Exit Sub
? ? End If
? ? If 標(biāo)題 = "" Or IsNull(標(biāo)題) = True Then
? ? MsgBox "標(biāo)題值為空!"
? ? 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 任務(wù)日程表 Where 任務(wù)ID=" & Me.任務(wù)ID
? ? Set search_rs = CurrentDb.OpenRecordset(search_sql, dbOpenDynaset)
? ? If search_rs.EOF = False Then
? ? search_rs.Edit
? ? search_rs!日期.Value = 日期.Value
? ? search_rs!時(shí)間段.Value = 時(shí)間段.Value
? ? search_rs!標(biāo)題.Value = 標(biāo)題.Value
? ? search_rs!內(nèi)容.Value = 內(nèi)容.Value
? ? search_rs!標(biāo)簽.Value = 標(biāo)簽.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.數(shù)據(jù)表子窗體.Requery
Else
? ? MsgBox "請(qǐng)選擇任務(wù)ID"
? ? Exit Sub
End If
End Sub
Private Sub Command查詢_Click()
Me.任務(wù)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 時(shí)間段 <> "" Then
? ? If filter_text <> "" Then
? ? filter_text = filter_text & " and " & "時(shí)間段 like '*" & Me.時(shí)間段 & "*'"
? ? Else
? ? filter_text = "時(shí)間段 like '*" & Me.時(shí)間段 & "*'"
? ? End If
End If
If 標(biāo)題 <> "" Then
? ? If filter_text <> "" Then
? ? filter_text = filter_text & " and " & "標(biāo)題 like '*" & Me.標(biāo)題 & "*'"
? ? Else
? ? filter_text = "標(biāo)題 like '*" & Me.標(biāo)題 & "*'"
? ? End If
End If
If 內(nèi)容 <> "" Then
? ? If filter_text <> "" Then
? ? filter_text = filter_text & " and " & "內(nèi)容 like '*" & Me.內(nèi)容 & "*'"
? ? Else
? ? filter_text = "內(nèi)容 like '*" & Me.內(nèi)容 & "*'"
? ? End If
End If
If 標(biāo)簽 <> "" Then
? ? If filter_text <> "" Then
? ? filter_text = filter_text & " and " & "標(biāo)簽 like '*" & Me.標(biāo)簽 & "*'"
? ? Else
? ? filter_text = "標(biāo)簽 like '*" & Me.標(biāo)簽 & "*'"
? ? 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.數(shù)據(jù)表子窗體.Form.Filter = filter_text
Me.數(shù)據(jù)表子窗體.Form.FilterOn = True
Else
Me.數(shù)據(jù)表子窗體.Form.FilterOn = False
End If
End Sub
Private Sub Command清空_Click()
任務(wù)ID.Value = ""
日期.Value = ""
時(shí)間段.Value = ""
標(biāo)題.Value = ""
內(nèi)容.Value = ""
標(biāo)簽.Value = ""
類別.Value = ""
重要程度.Value = ""
Me.是否完成 = False
End Sub
Private Sub Command全部_Click()
Me.任務(wù)ID = ""
Me.數(shù)據(jù)表子窗體.Form.FilterOn = False
End Sub
Private Sub Command刪除_Click()
If MsgBox("是否刪除該記錄", vbOKCancel) <> vbOK Then
Exit Sub
End If
If Me.任務(wù)ID <> "" Then
? ? DoCmd.SetWarnings (False)
? ? Dim del_sql As String
? ? del_sql = "Delete From 任務(wù)日程表 Where? 任務(wù)ID=" & Me.任務(wù)ID
? ? DoCmd.RunSQL del_sql
? ? MsgBox "刪除完成"
? ? Call Command清空_Click
? ? Me.數(shù)據(jù)表子窗體.Requery
Else
? ? MsgBox "請(qǐng)選擇任務(wù)ID"
? ? Exit Sub
End If
End Sub
Private Sub Command添加_Click()
On Error GoTo 添加失敗錯(cuò)誤
If 日期 = "" Or IsNull(日期) = True Then
MsgBox "日期值為空!"
Exit Sub
End If
If 標(biāo)題 = "" Or IsNull(標(biāo)題) = True Then
MsgBox "標(biāo)題值為空!"
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("任務(wù)日程表", dbOpenTable)
With add_rs
.AddNew
!日期.Value = 日期.Value
!時(shí)間段.Value = 時(shí)間段.Value
!標(biāo)題.Value = 標(biāo)題.Value
!內(nèi)容.Value = 內(nèi)容.Value
!標(biāo)簽.Value = 標(biāo)簽.Value
!類別.Value = 類別.Value
!重要程度.Value = 重要程度.Value
!是否完成.Value = 是否完成.Value
.Update
.Close
End With
Set add_rs = Nothing
MsgBox "添加成功!"
Me.數(shù)據(jù)表子窗體.Requery
Me.任務(wù)ID = ""
Exit Sub
添加失敗錯(cuò)誤:
MsgBox "添加失?。?#34;
End Sub
Private Sub Form_Load()
Me.是否完成 = False
End Sub