當前位置:編程學習大全網 - 編程語言 - 任務日程管理表格-VBA代碼

任務日程管理表格-VBA代碼

Private Sub 任務ID_DblClick(Cancel As Integer)

If Me.任務ID "" Then

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

Forms("任務日程管理").任務ID.Value = search_rs!任務ID.Value

Forms("任務日程管理").日期.Value = search_rs!日期.Value

Forms("任務日程管理").時間段.Value = search_rs!時間段.Value

Forms("任務日程管理").標題.Value = search_rs!標題.Value

Forms("任務日程管理").內容.Value = search_rs!內容.Value

Forms("任務日程管理").標簽.Value = search_rs!標簽.Value

Forms("任務日程管理").類別.Value = search_rs!類別.Value

Forms("任務日程管理").重要程度.Value = search_rs!重要程度.Value

Forms("任務日程管理").是否完成.Value = search_rs!是否完成.Value

End If

search_rs.Close

Set search_rs = Nothing

End If

End Sub

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

  • 上一篇:孤獨編程
  • 下一篇:150摩托車有多大馬力?
  • copyright 2024編程學習大全網