Repository navigation
Expand file tree
/
Copy pathForm_frmTaskList.cls
More file actions
217 lines (184 loc) · 6.19 KB
/
Copy pathForm_frmTaskList.cls
File metadata and controls
217 lines (184 loc) · 6.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
Attribute VB_Name = "Form_frmTaskList"
Attribute VB_Base = "0{5A9820A6-0EFE-442D-B414-22DC798F1A64}"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Attribute VB_TemplateDerived = False
Attribute VB_Customizable = False
Option Compare Database
Option Explicit
' =============================================================================
' Form_frmTaskList
' Continuous Form dashboard backed by AccessSQLiteDemo.db via the referenced
' AccessSQLite Class Library & ORM. Syncs filtered SQLite query results into
' tblTaskBuffer and writes inline row edits & actions straight back to SQLite.
' =============================================================================
Private m_SuppressSync As Boolean
Private Sub Form_Load()
On Error GoTo LoadErr
m_SuppressSync = True
Me!txtSearch.Value = vbNullString
Me!cboFilterCategory.Value = "(All)"
Me!cboFilterStatus.Value = "Active"
m_SuppressSync = False
RefreshFromSQLite 0
Exit Sub
LoadErr:
m_SuppressSync = False
End Sub
Public Sub RefreshFromSQLite(Optional ByVal lngSelectTaskId As Long = 0)
On Error GoTo RefreshErr
Dim strSearch As String
Dim strCat As String
Dim strStatus As String
Dim rstClone As DAO.Recordset
CommitPendingEditQuiet
strSearch = CStr(Nz(Me!txtSearch.Value, vbNullString))
strCat = CStr(Nz(Me!cboFilterCategory.Value, "(All)"))
strStatus = CStr(Nz(Me!cboFilterStatus.Value, "Active"))
SyncBufferFromSQLite strSearch, strCat, strStatus
Me.Requery
Me!lblBanner.Caption = GetSqliteSummaryBanner()
If StrComp(strStatus, "Trash (Soft-Deleted)", vbTextCompare) = 0 Then
Me!cmdDeleteSelected.Caption = "Restore Task"
Else
Me!cmdDeleteSelected.Caption = "Soft Delete"
End If
If lngSelectTaskId > 0 Then
Set rstClone = Me.RecordsetClone
If Not (rstClone.BOF And rstClone.EOF) Then
rstClone.FindFirst "[TaskID] = " & lngSelectTaskId
If Not rstClone.NoMatch Then
Me.Bookmark = rstClone.Bookmark
End If
End If
rstClone.Close
End If
Exit Sub
RefreshErr:
MsgBox "Failed to sync from SQLite: " & Err.Description, vbExclamation, "AccessSQLite Sync Error"
End Sub
Private Sub Form_Current()
On Error Resume Next
If Not (Me.RecordsetClone.BOF And Me.RecordsetClone.EOF) Then
If CBool(Nz(Me!IsDeletedRow, False)) Then
Me!cmdDeleteSelected.Caption = "Restore Task"
Else
Me!cmdDeleteSelected.Caption = "Soft Delete"
End If
End If
On Error GoTo 0
End Sub
' Writes any inline Continuous Form edit directly back into AccessSQLiteDemo.db via ORM Repository.
Private Sub Form_AfterUpdate()
On Error GoTo SaveRowErr
If m_SuppressSync Then Exit Sub
If IsNull(Me!txtRowTaskID.Value) Then Exit Sub
PushBufferRowToSQLite _
CLng(Me!txtRowTaskID.Value), _
CStr(Nz(Me!txtRowTitle.Value, vbNullString)), _
CStr(Nz(Me!cboRowCategory.Value, "General")), _
CStr(Nz(Me!cboRowPriority.Value, "Medium")), _
CCur(Nz(Me!txtRowCost.Value, 0@)), _
Me!txtRowDueDate.Value, _
CBool(Nz(Me!chkRowDone.Value, False))
Me!lblBanner.Caption = GetSqliteSummaryBanner()
Exit Sub
SaveRowErr:
MsgBox Err.Description, vbExclamation, "SQLite Inline Save Error"
RefreshFromSQLite CurrentSelectedTaskId()
End Sub
Private Sub chkRowDone_AfterUpdate()
CommitPendingEditQuiet
End Sub
Private Sub txtSearch_AfterUpdate()
If Not m_SuppressSync Then RefreshFromSQLite CurrentSelectedTaskId()
End Sub
Private Sub cboFilterCategory_AfterUpdate()
If Not m_SuppressSync Then RefreshFromSQLite 0
End Sub
Private Sub cboFilterStatus_AfterUpdate()
If Not m_SuppressSync Then RefreshFromSQLite 0
End Sub
Private Sub cmdApplyFilter_Click()
RefreshFromSQLite 0
End Sub
Private Sub cmdResetFilter_Click()
m_SuppressSync = True
Me!txtSearch.Value = vbNullString
Me!cboFilterCategory.Value = "(All)"
Me!cboFilterStatus.Value = "Active"
m_SuppressSync = False
RefreshFromSQLite 0
End Sub
Private Sub cmdRowOpenDetail_Click()
OpenDetailForSelectedRow
End Sub
Private Sub cmdEditSelected_Click()
OpenDetailForSelectedRow
End Sub
Private Sub cmdNewTask_Click()
CommitPendingEditQuiet
If CurrentProject.AllForms("frmTaskDetail").IsLoaded Then
Forms("frmTaskDetail").BeginNewTask
Forms("frmTaskDetail").SetFocus
Else
DoCmd.OpenForm "frmTaskDetail", acNormal, , , , , "NEW"
End If
End Sub
Private Sub cmdToggleSelected_Click()
Dim lngId As Long
lngId = CurrentSelectedTaskId()
If lngId <= 0 Then Exit Sub
CommitPendingEditQuiet
ToggleTaskCompletedInSQLite lngId
RefreshFromSQLite lngId
End Sub
Private Sub cmdDeleteSelected_Click()
Dim lngId As Long
lngId = CurrentSelectedTaskId()
If lngId <= 0 Then Exit Sub
CommitPendingEditQuiet
If CBool(Nz(Me!IsDeletedRow, False)) Then
TasksRepo().RestoreRecord lngId
RefreshFromSQLite lngId
Else
TasksRepo().DeleteRecord lngId, blnForceHardDelete:=False
RefreshFromSQLite 0
End If
End Sub
Private Sub cmdReloadSqlite_Click()
RefreshFromSQLite CurrentSelectedTaskId()
End Sub
Private Sub OpenDetailForSelectedRow()
Dim lngId As Long
lngId = CurrentSelectedTaskId()
If lngId <= 0 Then
cmdNewTask_Click
Exit Sub
End If
CommitPendingEditQuiet
If CurrentProject.AllForms("frmTaskDetail").IsLoaded Then
Forms("frmTaskDetail").LoadTaskFromSQLite lngId
Forms("frmTaskDetail").SetFocus
Else
DoCmd.OpenForm "frmTaskDetail", acNormal, , , , , CStr(lngId)
End If
End Sub
Private Sub CommitPendingEditQuiet()
On Error Resume Next
If Not (Me.RecordsetClone.BOF And Me.RecordsetClone.EOF) Then
If Me.Dirty Then Me.Dirty = False
End If
On Error GoTo 0
End Sub
Private Function CurrentSelectedTaskId() As Long
On Error Resume Next
If Not (Me.RecordsetClone.BOF And Me.RecordsetClone.EOF) Then
If Not IsNull(Me!txtRowTaskID.Value) Then
CurrentSelectedTaskId = CLng(Me!txtRowTaskID.Value)
End If
End If
On Error GoTo 0
End Function