Case 6: adding training records and checking leave
After a safety briefing in the warehouse, the records should be added with one click, and a leave request that exceeds the remaining days should not be saved at all.
In short: an append query INSERT INTO TrainingRecords … SELECT … WHERE Department = 'Warehouse' adds everyone at once. In Form_BeforeUpdate, DLookup minus Nz(DSum(…)) gives the remainder; if the request is larger, Cancel = True stops the save.
Task 1: records for a department
Task On 1 Dec 2026 the whole warehouse passed the health and safety training (TrainingID 1). Write the procedure SafetyWarehouse: with CurrentDb.Execute and dbFailOnError it appends a record for every active employee of the Warehouse department (TrainingID 1, date 1 Dec 2026, Passed Yes) and then shows “x records added”.
Employees 40 rows, 10 columns
| EmployeeID | EmployeeNo | FirstName | LastName | DepartmentID | ManagerID | HireDate | TermDate | WeeklyHours | LeaveDays |
|---|---|---|---|---|---|---|---|---|---|
| 1 | E1001 | Ella | Hill | 1 | 23 Dec 2013 | 40 | 25 | ||
| 2 | E1002 | Olivia | Taylor | 2 | 1 | 10 Sep 2013 | 40 | 25 | |
| 3 | E1003 | Grace | Wright | 3 | 1 | 22 Nov 2010 | 40 | 25 | |
| 4 | E1004 | Liam | Wright | 4 | 1 | 3 Mar 2015 | 40 | 25 | |
| 5 | E1005 | Ava | Wilson | 5 | 1 | 9 Sep 2014 | 40 | 25 | |
| 6 | E1006 | David | Wilson | 5 | 5 | 13 Dec 2013 | 20 | 13 | |
| 7 | E1007 | Liam | Evans | 4 | 4 | 4 May 2012 | 40 | 25 | |
| 8 | E1008 | Nina | Clark | 5 | 5 | 16 Jun 2024 | 11 Mar 2026 | 40 | 25 |
| 9 | E1009 | Leo | Clark | 5 | 5 | 12 Mar 2015 | 40 | 25 | |
| 10 | E1010 | Sophia | Johnson | 4 | 4 | 29 Nov 2025 | 40 | 25 | |
| 11 | E1011 | Liam | Taylor | 2 | 2 | 8 Sep 2019 | 40 | 25 | |
| 12 | E1012 | Chloe | Davies | 2 | 2 | 14 Jun 2020 | 40 | 25 | |
| 13 | E1013 | Henry | Smith | 2 | 2 | 2 Feb 2020 | 40 | 25 | |
| 14 | E1014 | Mia | Baker | 5 | 5 | 4 Apr 2019 | 40 | 25 | |
| 15 | E1015 | Jack | Young | 4 | 4 | 4 Mar 2017 | 40 | 25 | |
| 16 | E1016 | Mia | Ward | 5 | 5 | 4 Nov 2017 | 40 | 25 | |
| 17 | E1017 | Lucas | Brown | 2 | 2 | 17 Jan 2016 | 32 | 20 | |
| 18 | E1018 | Grace | Taylor | 4 | 4 | 22 Jan 2019 | 40 | 25 | |
| 19 | E1019 | Grace | King | 3 | 3 | 11 Sep 2016 | 30 Dec 2025 | 40 | 25 |
| 20 | E1020 | Mia | Johnson | 3 | 3 | 21 Sep 2020 | 32 | 20 | |
| 21 | E1021 | Noah | Brown | 3 | 3 | 28 Jul 2015 | 40 | 25 | |
| 22 | E1022 | Olivia | Hill | 3 | 3 | 9 Sep 2010 | 20 | 13 | |
| 23 | E1023 | Sam | Taylor | 3 | 3 | 4 Jun 2022 | 40 | 25 | |
| 24 | E1024 | Liam | King | 5 | 5 | 8 Aug 2021 | 40 | 25 | |
| 25 | E1025 | Oliver | Ward | 4 | 4 | 8 Dec 2013 | 40 | 25 | |
| 26 | E1026 | Chloe | Johnson | 4 | 4 | 18 Oct 2013 | 40 | 25 | |
| 27 | E1027 | Ella | Davies | 3 | 3 | 21 Nov 2011 | 40 | 25 | |
| 28 | E1028 | Jack | Taylor | 5 | 5 | 10 May 2010 | 32 | 20 | |
| 29 | E1029 | Oliver | Brown | 2 | 2 | 12 Jun 2012 | 30 | 19 | |
| 30 | E1030 | Noah | Hall | 4 | 4 | 24 Jul 2021 | 40 | 25 | |
| 31 | E1031 | Jack | Walker | 5 | 5 | 27 Mar 2014 | 27 Dec 2025 | 30 | 19 |
| 32 | E1032 | Grace | Baker | 5 | 5 | 7 Dec 2022 | 20 | 13 | |
| 33 | E1033 | Oliver | Davies | 4 | 4 | 6 Aug 2012 | 40 | 25 | |
| 34 | E1034 | Sam | Davies | 5 | 5 | 11 May 2026 | 40 | 25 | |
| 35 | E1035 | Emma | Davies | 4 | 4 | 20 Oct 2025 | 30 | 19 | |
| 36 | E1036 | Mia | Wright | 5 | 5 | 16 May 2021 | 40 | 25 | |
| 37 | E1037 | Leo | Johnson | 4 | 4 | 21 Jun 2026 | 40 | 25 | |
| 38 | E1038 | David | Hughes | 5 | 5 | 8 Dec 2025 | 40 | 25 | |
| 39 | E1039 | Emma | Wright | 4 | 4 | 3 Jul 2026 | 32 | 20 | |
| 40 | E1040 | Chloe | Ward | 3 | 3 | 3 Apr 2025 | 32 | 20 |
Departments 5 rows, 3 columns
| DepartmentID | Department | CostCenter |
|---|---|---|
| 1 | Management | 100 |
| 2 | Sales | 200 |
| 3 | Warehouse | 300 |
| 4 | Administration | 400 |
| 5 | IT | 500 |
TrainingRecords 271 rows, 5 columns
| RecordID | EmployeeID | TrainingID | CompletedOn | Passed |
|---|---|---|---|---|
| 1 | 2 | 2 | 22 Jan 2024 | ☑ |
| 2 | 3 | 2 | 22 Jan 2024 | ☑ |
| 3 | 9 | 2 | 30 Jan 2024 | ☑ |
| 4 | 27 | 1 | 1 Feb 2024 | ☑ |
| 5 | 13 | 1 | 5 Feb 2024 | ☑ |
| 6 | 11 | 1 | 8 Feb 2024 | ☑ |
| 7 | 33 | 2 | 15 Feb 2024 | ☑ |
| 8 | 11 | 2 | 18 Feb 2024 | ☑ |
| 9 | 14 | 2 | 18 Feb 2024 | ☐ |
| 10 | 3 | 3 | 5 Mar 2024 | ☑ |
| 11 | 20 | 1 | 11 Mar 2024 | ☑ |
| 12 | 21 | 2 | 15 Mar 2024 | ☑ |
| 13 | 18 | 2 | 16 Mar 2024 | ☑ |
| 14 | 22 | 1 | 23 Mar 2024 | ☑ |
| 15 | 6 | 3 | 26 Mar 2024 | ☑ |
| 16 | 4 | 1 | 27 Mar 2024 | ☑ |
| 17 | 31 | 1 | 29 Mar 2024 | ☑ |
| 18 | 32 | 3 | 29 Mar 2024 | ☐ |
| 19 | 36 | 3 | 3 Apr 2024 | ☑ |
| 20 | 6 | 2 | 4 Apr 2024 | ☑ |
| 21 | 23 | 3 | 11 Apr 2024 | ☑ |
| 22 | 7 | 3 | 13 Apr 2024 | ☑ |
| 23 | 5 | 2 | 15 Apr 2024 | ☑ |
| 24 | 24 | 2 | 17 Apr 2024 | ☑ |
| 25 | 13 | 2 | 30 Apr 2024 | ☑ |
| 26 | 22 | 3 | 2 May 2024 | ☑ |
| 27 | 32 | 3 | 6 May 2024 | ☑ |
| 28 | 20 | 2 | 7 May 2024 | ☑ |
| 29 | 29 | 3 | 9 May 2024 | ☐ |
| 30 | 2 | 3 | 18 May 2024 | ☑ |
| 31 | 26 | 3 | 22 May 2024 | ☑ |
| 32 | 32 | 1 | 23 May 2024 | ☑ |
| 33 | 15 | 3 | 28 May 2024 | ☑ |
| 34 | 24 | 3 | 28 May 2024 | ☑ |
| 35 | 21 | 3 | 30 May 2024 | ☑ |
| 36 | 23 | 2 | 30 May 2024 | ☑ |
| 37 | 12 | 2 | 2 Jun 2024 | ☑ |
| 38 | 17 | 3 | 4 Jun 2024 | ☑ |
| 39 | 29 | 3 | 8 Jun 2024 | ☑ |
| 40 | 14 | 1 | 14 Jun 2024 | ☑ |
| 41 | 4 | 2 | 16 Jun 2024 | ☑ |
| 42 | 20 | 3 | 16 Jun 2024 | ☑ |
| 43 | 25 | 2 | 16 Jun 2024 | ☑ |
| 44 | 28 | 2 | 18 Jun 2024 | ☑ |
| 45 | 1 | 3 | 20 Jun 2024 | ☑ |
| 46 | 14 | 3 | 22 Jun 2024 | ☑ |
| 47 | 5 | 3 | 25 Jun 2024 | ☑ |
| 48 | 16 | 3 | 25 Jun 2024 | ☑ |
| 49 | 22 | 2 | 27 Jun 2024 | ☑ |
| 50 | 33 | 1 | 1 Jul 2024 | ☑ |
| 51 | 3 | 1 | 2 Jul 2024 | ☑ |
| 52 | 16 | 2 | 2 Jul 2024 | ☑ |
| 53 | 2 | 1 | 6 Jul 2024 | ☐ |
| 54 | 1 | 2 | 8 Jul 2024 | ☑ |
| 55 | 24 | 1 | 8 Jul 2024 | ☑ |
| 56 | 27 | 2 | 12 Jul 2024 | ☑ |
| 57 | 26 | 1 | 13 Jul 2024 | ☑ |
| 58 | 9 | 3 | 15 Jul 2024 | ☑ |
| 59 | 31 | 2 | 21 Jul 2024 | ☑ |
| 60 | 16 | 1 | 22 Jul 2024 | ☑ |
| 61 | 26 | 2 | 26 Jul 2024 | ☑ |
| 62 | 7 | 2 | 30 Jul 2024 | ☑ |
| 63 | 28 | 3 | 1 Aug 2024 | ☑ |
| 64 | 17 | 1 | 12 Aug 2024 | ☑ |
| 65 | 23 | 1 | 12 Aug 2024 | ☑ |
| 66 | 17 | 2 | 13 Aug 2024 | ☑ |
| 67 | 29 | 2 | 16 Aug 2024 | ☑ |
| 68 | 31 | 3 | 20 Aug 2024 | ☑ |
| 69 | 8 | 2 | 25 Aug 2024 | ☑ |
| 70 | 9 | 1 | 27 Aug 2024 | ☑ |
| 71 | 19 | 1 | 1 Sep 2024 | ☑ |
| 72 | 32 | 2 | 5 Sep 2024 | ☑ |
| 73 | 36 | 1 | 9 Sep 2024 | ☑ |
| 74 | 25 | 1 | 11 Sep 2024 | ☐ |
| 75 | 19 | 3 | 21 Sep 2024 | ☑ |
| 76 | 29 | 1 | 23 Sep 2024 | ☑ |
| 77 | 12 | 1 | 28 Sep 2024 | ☑ |
| 78 | 30 | 2 | 28 Sep 2024 | ☑ |
| 79 | 33 | 3 | 30 Sep 2024 | ☑ |
| 80 | 5 | 1 | 2 Oct 2024 | ☑ |
| 81 | 7 | 1 | 2 Oct 2024 | ☑ |
| 82 | 18 | 3 | 5 Oct 2024 | ☑ |
| 83 | 15 | 1 | 9 Oct 2024 | ☑ |
| 84 | 13 | 3 | 11 Oct 2024 | ☑ |
| 85 | 4 | 3 | 17 Oct 2024 | ☑ |
| 86 | 25 | 1 | 20 Oct 2024 | ☑ |
| 87 | 28 | 1 | 21 Oct 2024 | ☑ |
| 88 | 12 | 3 | 25 Oct 2024 | ☑ |
| 89 | 25 | 3 | 7 Nov 2024 | ☑ |
| 90 | 36 | 2 | 19 Nov 2024 | ☑ |
| 91 | 30 | 1 | 20 Nov 2024 | ☑ |
| 92 | 19 | 1 | 16 Jan 2025 | ☑ |
| 93 | 30 | 2 | 20 Jan 2025 | ☑ |
| 94 | 16 | 1 | 27 Jan 2025 | ☑ |
| 95 | 13 | 4 | 30 Jan 2025 | ☑ |
| 96 | 19 | 2 | 18 Feb 2025 | ☑ |
| 97 | 36 | 2 | 21 Feb 2025 | ☑ |
| 98 | 18 | 5 | 6 Mar 2025 | ☐ |
| 99 | 22 | 4 | 9 Mar 2025 | ☑ |
| 100 | 24 | 1 | 9 Mar 2025 | ☑ |
| 101 | 22 | 2 | 10 Mar 2025 | ☑ |
| 102 | 33 | 1 | 16 Mar 2025 | ☑ |
| 103 | 13 | 2 | 17 Mar 2025 | ☑ |
| 104 | 15 | 2 | 21 Mar 2025 | ☑ |
| 105 | 11 | 2 | 22 Mar 2025 | ☑ |
| 106 | 33 | 2 | 26 Mar 2025 | ☑ |
| 107 | 27 | 1 | 27 Mar 2025 | ☑ |
| 108 | 7 | 5 | 31 Mar 2025 | ☑ |
| 109 | 8 | 1 | 2 Apr 2025 | ☑ |
| 110 | 14 | 2 | 4 Apr 2025 | ☑ |
| 111 | 11 | 5 | 6 Apr 2025 | ☑ |
| 112 | 14 | 4 | 6 Apr 2025 | ☑ |
| 113 | 3 | 2 | 22 Apr 2025 | ☑ |
| 114 | 19 | 5 | 28 Apr 2025 | ☑ |
| 115 | 7 | 4 | 5 May 2025 | ☑ |
| 116 | 18 | 2 | 10 May 2025 | ☑ |
| 117 | 26 | 1 | 13 May 2025 | ☑ |
| 118 | 14 | 1 | 14 May 2025 | ☑ |
| 119 | 5 | 2 | 18 May 2025 | ☑ |
| 120 | 40 | 1 | 19 May 2025 | ☑ |
| 121 | 11 | 1 | 21 May 2025 | ☑ |
| 122 | 20 | 1 | 22 May 2025 | ☑ |
| 123 | 31 | 1 | 22 May 2025 | ☑ |
| 124 | 18 | 4 | 25 May 2025 | ☑ |
| 125 | 9 | 1 | 31 May 2025 | ☑ |
| 126 | 24 | 2 | 4 Jun 2025 | ☑ |
| 127 | 29 | 1 | 5 Jun 2025 | ☑ |
| 128 | 32 | 1 | 5 Jun 2025 | ☑ |
| 129 | 23 | 1 | 9 Jun 2025 | ☑ |
| 130 | 4 | 2 | 14 Jun 2025 | ☑ |
| 131 | 9 | 2 | 21 Jun 2025 | ☑ |
| 132 | 17 | 2 | 28 Jun 2025 | ☑ |
| 133 | 27 | 2 | 28 Jun 2025 | ☑ |
| 134 | 8 | 2 | 1 Jul 2025 | ☑ |
| 135 | 20 | 2 | 5 Jul 2025 | ☑ |
| 136 | 36 | 1 | 5 Jul 2025 | ☑ |
| 137 | 28 | 2 | 12 Jul 2025 | ☑ |
| 138 | 8 | 5 | 17 Jul 2025 | ☑ |
| 139 | 4 | 4 | 19 Jul 2025 | ☑ |
| 140 | 23 | 4 | 21 Jul 2025 | ☑ |
| 141 | 5 | 1 | 25 Jul 2025 | ☑ |
| 142 | 16 | 2 | 26 Jul 2025 | ☑ |
| 143 | 32 | 2 | 29 Jul 2025 | ☐ |
| 144 | 25 | 2 | 6 Aug 2025 | ☑ |
| 145 | 7 | 1 | 18 Aug 2025 | ☑ |
| 146 | 8 | 4 | 23 Aug 2025 | ☑ |
| 147 | 18 | 1 | 1 Sep 2025 | ☑ |
| 148 | 29 | 2 | 4 Sep 2025 | ☑ |
| 149 | 32 | 2 | 4 Sep 2025 | ☑ |
| 150 | 7 | 2 | 5 Sep 2025 | ☑ |
| 151 | 17 | 4 | 5 Sep 2025 | ☑ |
| 152 | 2 | 2 | 6 Sep 2025 | ☑ |
| 153 | 28 | 1 | 7 Sep 2025 | ☑ |
| 154 | 40 | 4 | 18 Sep 2025 | ☑ |
| 155 | 3 | 5 | 19 Sep 2025 | ☑ |
| 156 | 6 | 1 | 24 Sep 2025 | ☑ |
| 157 | 33 | 5 | 25 Sep 2025 | ☑ |
| 158 | 4 | 1 | 27 Sep 2025 | ☑ |
| 159 | 23 | 2 | 7 Oct 2025 | ☑ |
| 160 | 1 | 1 | 14 Oct 2025 | ☑ |
| 161 | 21 | 1 | 21 Oct 2025 | ☑ |
| 162 | 3 | 1 | 30 Oct 2025 | ☑ |
| 163 | 25 | 1 | 2 Nov 2025 | ☑ |
| 164 | 30 | 5 | 2 Nov 2025 | ☑ |
| 165 | 1 | 2 | 12 Nov 2025 | ☑ |
| 166 | 2 | 6 | 15 Nov 2025 | ☑ |
| 167 | 15 | 1 | 15 Nov 2025 | ☑ |
| 168 | 30 | 4 | 15 Nov 2025 | ☑ |
| 169 | 6 | 2 | 16 Nov 2025 | ☑ |
| 170 | 14 | 5 | 20 Nov 2025 | ☑ |
| 171 | 25 | 1 | 26 Jan 2026 | ☑ |
| 172 | 24 | 2 | 27 Jan 2026 | ☑ |
| 173 | 36 | 1 | 1 Feb 2026 | ☑ |
| 174 | 20 | 2 | 4 Feb 2026 | ☑ |
| 175 | 7 | 2 | 8 Feb 2026 | ☑ |
| 176 | 35 | 1 | 12 Feb 2026 | ☐ |
| 177 | 38 | 2 | 14 Feb 2026 | ☑ |
| 178 | 16 | 3 | 15 Feb 2026 | ☑ |
| 179 | 20 | 3 | 18 Feb 2026 | ☑ |
| 180 | 29 | 1 | 21 Feb 2026 | ☑ |
| 181 | 32 | 3 | 2 Mar 2026 | ☑ |
| 182 | 13 | 1 | 9 Mar 2026 | ☑ |
| 183 | 21 | 3 | 10 Mar 2026 | ☐ |
| 184 | 26 | 3 | 12 Mar 2026 | ☑ |
| 185 | 6 | 2 | 14 Mar 2026 | ☑ |
| 186 | 27 | 2 | 16 Mar 2026 | ☑ |
| 187 | 3 | 2 | 24 Mar 2026 | ☑ |
| 188 | 35 | 1 | 24 Mar 2026 | ☑ |
| 189 | 14 | 1 | 25 Mar 2026 | ☑ |
| 190 | 13 | 3 | 2 Apr 2026 | ☑ |
| 191 | 5 | 3 | 5 Apr 2026 | ☑ |
| 192 | 9 | 2 | 8 Apr 2026 | ☑ |
| 193 | 33 | 3 | 8 Apr 2026 | ☑ |
| 194 | 21 | 3 | 13 Apr 2026 | ☑ |
| 195 | 22 | 1 | 15 Apr 2026 | ☑ |
| 196 | 16 | 2 | 18 Apr 2026 | ☐ |
| 197 | 33 | 1 | 21 Apr 2026 | ☑ |
| 198 | 29 | 3 | 22 Apr 2026 | ☑ |
| 199 | 23 | 2 | 27 Apr 2026 | ☑ |
| 200 | 27 | 1 | 29 Apr 2026 | ☑ |
| 201 | 28 | 2 | 29 Apr 2026 | ☑ |
| 202 | 38 | 3 | 29 Apr 2026 | ☑ |
| 203 | 12 | 3 | 8 May 2026 | ☐ |
| 204 | 23 | 3 | 14 May 2026 | ☑ |
| 205 | 9 | 1 | 15 May 2026 | ☑ |
| 206 | 40 | 3 | 20 May 2026 | ☑ |
| 207 | 16 | 2 | 26 May 2026 | ☑ |
| 208 | 30 | 3 | 28 May 2026 | ☑ |
| 209 | 29 | 2 | 2 Jun 2026 | ☑ |
| 210 | 12 | 3 | 4 Jun 2026 | ☑ |
| 211 | 26 | 2 | 4 Jun 2026 | ☑ |
| 212 | 25 | 3 | 5 Jun 2026 | ☑ |
| 213 | 6 | 1 | 7 Jun 2026 | ☑ |
| 214 | 23 | 1 | 7 Jun 2026 | ☑ |
| 215 | 24 | 3 | 8 Jun 2026 | ☑ |
| 216 | 10 | 3 | 9 Jun 2026 | ☑ |
| 217 | 27 | 3 | 9 Jun 2026 | ☑ |
| 218 | 2 | 1 | 10 Jun 2026 | ☑ |
| 219 | 7 | 3 | 11 Jun 2026 | ☐ |
| 220 | 17 | 3 | 12 Jun 2026 | ☑ |
| 221 | 1 | 3 | 18 Jun 2026 | ☐ |
| 222 | 28 | 1 | 20 Jun 2026 | ☑ |
| 223 | 18 | 2 | 22 Jun 2026 | ☑ |
| 224 | 1 | 1 | 25 Jun 2026 | ☐ |
| 225 | 36 | 3 | 30 Jun 2026 | ☑ |
| 226 | 38 | 1 | 2 Jul 2026 | ☑ |
| 227 | 21 | 1 | 9 Jul 2026 | ☑ |
| 228 | 15 | 1 | 16 Jul 2026 | ☑ |
| 229 | 26 | 1 | 16 Jul 2026 | ☑ |
| 230 | 24 | 1 | 19 Jul 2026 | ☑ |
| 231 | 28 | 3 | 21 Jul 2026 | ☑ |
| 232 | 1 | 2 | 22 Jul 2026 | ☑ |
| 233 | 30 | 2 | 25 Jul 2026 | ☑ |
| 234 | 4 | 3 | 2 Aug 2026 | ☑ |
| 235 | 10 | 2 | 2 Aug 2026 | ☑ |
| 236 | 17 | 2 | 2 Aug 2026 | ☐ |
| 237 | 32 | 2 | 2 Aug 2026 | ☑ |
| 238 | 40 | 1 | 2 Aug 2026 | ☑ |
| 239 | 18 | 1 | 5 Aug 2026 | ☑ |
| 240 | 11 | 3 | 15 Aug 2026 | ☑ |
| 241 | 12 | 2 | 16 Aug 2026 | ☑ |
| 242 | 18 | 3 | 26 Aug 2026 | ☑ |
| 243 | 2 | 3 | 30 Aug 2026 | ☑ |
| 244 | 40 | 2 | 1 Sep 2026 | ☑ |
| 245 | 34 | 3 | 3 Sep 2026 | ☑ |
| 246 | 39 | 1 | 3 Sep 2026 | ☑ |
| 247 | 10 | 1 | 11 Sep 2026 | ☐ |
| 248 | 15 | 3 | 11 Sep 2026 | ☑ |
| 249 | 14 | 2 | 15 Sep 2026 | ☐ |
| 250 | 20 | 1 | 16 Sep 2026 | ☑ |
| 251 | 4 | 2 | 17 Sep 2026 | ☑ |
| 252 | 30 | 1 | 21 Sep 2026 | ☑ |
| 253 | 7 | 1 | 24 Sep 2026 | ☑ |
| 254 | 34 | 2 | 24 Sep 2026 | ☑ |
| 255 | 13 | 2 | 1 Oct 2026 | ☑ |
| 256 | 9 | 3 | 5 Oct 2026 | ☑ |
| 257 | 22 | 3 | 5 Oct 2026 | ☑ |
| 258 | 35 | 3 | 5 Oct 2026 | ☑ |
| 259 | 32 | 1 | 10 Oct 2026 | ☑ |
| 260 | 16 | 1 | 12 Oct 2026 | ☑ |
| 261 | 22 | 2 | 14 Oct 2026 | ☑ |
| 262 | 14 | 2 | 18 Oct 2026 | ☑ |
| 263 | 6 | 3 | 21 Oct 2026 | ☑ |
| 264 | 17 | 1 | 21 Oct 2026 | ☑ |
| 265 | 2 | 2 | 23 Oct 2026 | ☑ |
| 266 | 25 | 2 | 27 Oct 2026 | ☑ |
| 267 | 3 | 3 | 6 Nov 2026 | ☑ |
| 268 | 34 | 1 | 8 Nov 2026 | ☑ |
| 269 | 11 | 1 | 9 Nov 2026 | ☑ |
| 270 | 3 | 1 | 17 Nov 2026 | ☑ |
| 271 | 12 | 1 | 20 Nov 2026 | ☑ |
The lesson on VBA in Access shows Execute and RecordsAffected.
Task 2: checking a leave request
Task The form frmAbsence should not save leave that exceeds the remaining allowance. Write Form_BeforeUpdate: if AbsenceType is “Leave”, calculate the remainder (the employee's LeaveDays via DLookup minus their leave days so far via DSum, with Nz). If the days in the form are more than the remainder, show “Only x days of leave left.” and cancel the save.
Employees 40 rows, 10 columns
| EmployeeID | EmployeeNo | FirstName | LastName | DepartmentID | ManagerID | HireDate | TermDate | WeeklyHours | LeaveDays |
|---|---|---|---|---|---|---|---|---|---|
| 1 | E1001 | Ella | Hill | 1 | 23 Dec 2013 | 40 | 25 | ||
| 2 | E1002 | Olivia | Taylor | 2 | 1 | 10 Sep 2013 | 40 | 25 | |
| 3 | E1003 | Grace | Wright | 3 | 1 | 22 Nov 2010 | 40 | 25 | |
| 4 | E1004 | Liam | Wright | 4 | 1 | 3 Mar 2015 | 40 | 25 | |
| 5 | E1005 | Ava | Wilson | 5 | 1 | 9 Sep 2014 | 40 | 25 | |
| 6 | E1006 | David | Wilson | 5 | 5 | 13 Dec 2013 | 20 | 13 | |
| 7 | E1007 | Liam | Evans | 4 | 4 | 4 May 2012 | 40 | 25 | |
| 8 | E1008 | Nina | Clark | 5 | 5 | 16 Jun 2024 | 11 Mar 2026 | 40 | 25 |
| 9 | E1009 | Leo | Clark | 5 | 5 | 12 Mar 2015 | 40 | 25 | |
| 10 | E1010 | Sophia | Johnson | 4 | 4 | 29 Nov 2025 | 40 | 25 | |
| 11 | E1011 | Liam | Taylor | 2 | 2 | 8 Sep 2019 | 40 | 25 | |
| 12 | E1012 | Chloe | Davies | 2 | 2 | 14 Jun 2020 | 40 | 25 | |
| 13 | E1013 | Henry | Smith | 2 | 2 | 2 Feb 2020 | 40 | 25 | |
| 14 | E1014 | Mia | Baker | 5 | 5 | 4 Apr 2019 | 40 | 25 | |
| 15 | E1015 | Jack | Young | 4 | 4 | 4 Mar 2017 | 40 | 25 | |
| 16 | E1016 | Mia | Ward | 5 | 5 | 4 Nov 2017 | 40 | 25 | |
| 17 | E1017 | Lucas | Brown | 2 | 2 | 17 Jan 2016 | 32 | 20 | |
| 18 | E1018 | Grace | Taylor | 4 | 4 | 22 Jan 2019 | 40 | 25 | |
| 19 | E1019 | Grace | King | 3 | 3 | 11 Sep 2016 | 30 Dec 2025 | 40 | 25 |
| 20 | E1020 | Mia | Johnson | 3 | 3 | 21 Sep 2020 | 32 | 20 | |
| 21 | E1021 | Noah | Brown | 3 | 3 | 28 Jul 2015 | 40 | 25 | |
| 22 | E1022 | Olivia | Hill | 3 | 3 | 9 Sep 2010 | 20 | 13 | |
| 23 | E1023 | Sam | Taylor | 3 | 3 | 4 Jun 2022 | 40 | 25 | |
| 24 | E1024 | Liam | King | 5 | 5 | 8 Aug 2021 | 40 | 25 | |
| 25 | E1025 | Oliver | Ward | 4 | 4 | 8 Dec 2013 | 40 | 25 | |
| 26 | E1026 | Chloe | Johnson | 4 | 4 | 18 Oct 2013 | 40 | 25 | |
| 27 | E1027 | Ella | Davies | 3 | 3 | 21 Nov 2011 | 40 | 25 | |
| 28 | E1028 | Jack | Taylor | 5 | 5 | 10 May 2010 | 32 | 20 | |
| 29 | E1029 | Oliver | Brown | 2 | 2 | 12 Jun 2012 | 30 | 19 | |
| 30 | E1030 | Noah | Hall | 4 | 4 | 24 Jul 2021 | 40 | 25 | |
| 31 | E1031 | Jack | Walker | 5 | 5 | 27 Mar 2014 | 27 Dec 2025 | 30 | 19 |
| 32 | E1032 | Grace | Baker | 5 | 5 | 7 Dec 2022 | 20 | 13 | |
| 33 | E1033 | Oliver | Davies | 4 | 4 | 6 Aug 2012 | 40 | 25 | |
| 34 | E1034 | Sam | Davies | 5 | 5 | 11 May 2026 | 40 | 25 | |
| 35 | E1035 | Emma | Davies | 4 | 4 | 20 Oct 2025 | 30 | 19 | |
| 36 | E1036 | Mia | Wright | 5 | 5 | 16 May 2021 | 40 | 25 | |
| 37 | E1037 | Leo | Johnson | 4 | 4 | 21 Jun 2026 | 40 | 25 | |
| 38 | E1038 | David | Hughes | 5 | 5 | 8 Dec 2025 | 40 | 25 | |
| 39 | E1039 | Emma | Wright | 4 | 4 | 3 Jul 2026 | 32 | 20 | |
| 40 | E1040 | Chloe | Ward | 3 | 3 | 3 Apr 2025 | 32 | 20 |
Absences 144 rows, 6 columns
| AbsenceID | EmployeeID | StartDate | EndDate | AbsenceType | Days |
|---|---|---|---|---|---|
| 1 | 28 | 6 Jan 2026 | 9 Jan 2026 | Leave | 4 |
| 2 | 1 | 14 Jan 2026 | 23 Jan 2026 | Leave | 8 |
| 3 | 26 | 16 Jan 2026 | 21 Jan 2026 | Sick | 4 |
| 4 | 8 | 19 Jan 2026 | 22 Jan 2026 | Leave | 4 |
| 5 | 25 | 23 Jan 2026 | 27 Jan 2026 | Leave | 3 |
| 6 | 4 | 26 Jan 2026 | 5 Feb 2026 | Leave | 9 |
| 7 | 27 | 26 Jan 2026 | 29 Jan 2026 | Leave | 4 |
| 8 | 17 | 5 Feb 2026 | 10 Feb 2026 | Leave | 4 |
| 9 | 1 | 6 Feb 2026 | 13 Feb 2026 | Leave | 6 |
| 10 | 3 | 6 Feb 2026 | 13 Feb 2026 | Leave | 6 |
| 11 | 18 | 9 Feb 2026 | 12 Feb 2026 | Leave | 4 |
| 12 | 18 | 16 Feb 2026 | 16 Feb 2026 | Sick | 1 |
| 13 | 22 | 16 Feb 2026 | 18 Feb 2026 | Leave | 3 |
| 14 | 40 | 16 Feb 2026 | 25 Feb 2026 | Leave | 8 |
| 15 | 7 | 17 Feb 2026 | 18 Feb 2026 | Sick | 2 |
| 16 | 22 | 19 Feb 2026 | 2 Mar 2026 | Leave | 8 |
| 17 | 17 | 23 Feb 2026 | 27 Feb 2026 | Leave | 5 |
| 18 | 12 | 24 Feb 2026 | 4 Mar 2026 | Leave | 7 |
| 19 | 4 | 25 Feb 2026 | 26 Feb 2026 | Leave | 2 |
| 20 | 32 | 27 Feb 2026 | 12 Mar 2026 | Leave | 10 |
| 21 | 8 | 2 Mar 2026 | 6 Mar 2026 | Leave | 5 |
| 22 | 13 | 2 Mar 2026 | 11 Mar 2026 | Leave | 8 |
| 23 | 15 | 2 Mar 2026 | 11 Mar 2026 | Leave | 8 |
| 24 | 6 | 3 Mar 2026 | 11 Mar 2026 | Leave | 7 |
| 25 | 9 | 4 Mar 2026 | 5 Mar 2026 | Sick | 2 |
| 26 | 14 | 5 Mar 2026 | 13 Mar 2026 | Leave | 7 |
| 27 | 21 | 5 Mar 2026 | 13 Mar 2026 | Leave | 7 |
| 28 | 20 | 6 Mar 2026 | 9 Mar 2026 | Sick | 2 |
| 29 | 27 | 9 Mar 2026 | 9 Mar 2026 | Sick | 1 |
| 30 | 35 | 9 Mar 2026 | 9 Mar 2026 | Sick | 1 |
| 31 | 40 | 17 Mar 2026 | 17 Mar 2026 | Sick | 1 |
| 32 | 4 | 18 Mar 2026 | 19 Mar 2026 | Sick | 2 |
| 33 | 26 | 18 Mar 2026 | 23 Mar 2026 | Leave | 4 |
| 34 | 3 | 19 Mar 2026 | 31 Mar 2026 | Leave | 9 |
| 35 | 18 | 23 Mar 2026 | 24 Mar 2026 | Leave | 2 |
| 36 | 2 | 26 Mar 2026 | 27 Mar 2026 | Leave | 2 |
| 37 | 1 | 30 Mar 2026 | 2 Apr 2026 | Leave | 4 |
| 38 | 38 | 30 Mar 2026 | 2 Apr 2026 | Leave | 4 |
| 39 | 23 | 6 Apr 2026 | 10 Apr 2026 | Sick | 5 |
| 40 | 33 | 7 Apr 2026 | 20 Apr 2026 | Leave | 10 |
| 41 | 9 | 13 Apr 2026 | 22 Apr 2026 | Leave | 8 |
| 42 | 18 | 13 Apr 2026 | 14 Apr 2026 | Sick | 2 |
| 43 | 25 | 13 Apr 2026 | 13 Apr 2026 | Sick | 1 |
| 44 | 27 | 16 Apr 2026 | 29 Apr 2026 | Leave | 10 |
| 45 | 40 | 16 Apr 2026 | 22 Apr 2026 | Sick | 5 |
| 46 | 26 | 17 Apr 2026 | 23 Apr 2026 | Leave | 5 |
| 47 | 12 | 28 Apr 2026 | 29 Apr 2026 | Leave | 2 |
| 48 | 13 | 29 Apr 2026 | 29 Apr 2026 | Sick | 1 |
| 49 | 15 | 6 May 2026 | 8 May 2026 | Sick | 3 |
| 50 | 4 | 11 May 2026 | 21 May 2026 | Leave | 9 |
| 51 | 9 | 11 May 2026 | 12 May 2026 | Leave | 2 |
| 52 | 36 | 12 May 2026 | 20 May 2026 | Leave | 7 |
| 53 | 27 | 13 May 2026 | 21 May 2026 | Leave | 7 |
| 54 | 18 | 14 May 2026 | 20 May 2026 | Sick | 5 |
| 55 | 28 | 14 May 2026 | 14 May 2026 | Sick | 1 |
| 56 | 9 | 18 May 2026 | 29 May 2026 | Leave | 10 |
| 57 | 21 | 19 May 2026 | 28 May 2026 | Leave | 8 |
| 58 | 33 | 20 May 2026 | 26 May 2026 | Sick | 5 |
| 59 | 13 | 21 May 2026 | 26 May 2026 | Leave | 4 |
| 60 | 20 | 21 May 2026 | 28 May 2026 | Leave | 6 |
| 61 | 38 | 21 May 2026 | 29 May 2026 | Leave | 7 |
| 62 | 28 | 22 May 2026 | 26 May 2026 | Leave | 3 |
| 63 | 26 | 26 May 2026 | 27 May 2026 | Sick | 2 |
| 64 | 29 | 29 May 2026 | 1 Jun 2026 | Sick | 2 |
| 65 | 33 | 5 Jun 2026 | 5 Jun 2026 | Sick | 1 |
| 66 | 38 | 5 Jun 2026 | 11 Jun 2026 | Leave | 5 |
| 67 | 30 | 9 Jun 2026 | 11 Jun 2026 | Leave | 3 |
| 68 | 3 | 11 Jun 2026 | 15 Jun 2026 | Sick | 3 |
| 69 | 12 | 15 Jun 2026 | 15 Jun 2026 | Sick | 1 |
| 70 | 23 | 15 Jun 2026 | 25 Jun 2026 | Leave | 9 |
| 71 | 7 | 17 Jun 2026 | 22 Jun 2026 | Leave | 4 |
| 72 | 14 | 17 Jun 2026 | 19 Jun 2026 | Leave | 3 |
| 73 | 15 | 17 Jun 2026 | 25 Jun 2026 | Leave | 7 |
| 74 | 34 | 18 Jun 2026 | 30 Jun 2026 | Leave | 9 |
| 75 | 5 | 23 Jun 2026 | 30 Jun 2026 | Leave | 6 |
| 76 | 17 | 23 Jun 2026 | 25 Jun 2026 | Sick | 3 |
| 77 | 29 | 23 Jun 2026 | 24 Jun 2026 | Leave | 2 |
| 78 | 32 | 29 Jun 2026 | 30 Jun 2026 | Leave | 2 |
| 79 | 15 | 30 Jun 2026 | 6 Jul 2026 | Leave | 5 |
| 80 | 13 | 1 Jul 2026 | 13 Jul 2026 | Leave | 9 |
| 81 | 11 | 6 Jul 2026 | 9 Jul 2026 | Sick | 4 |
| 82 | 17 | 6 Jul 2026 | 9 Jul 2026 | Leave | 4 |
| 83 | 30 | 9 Jul 2026 | 17 Jul 2026 | Leave | 7 |
| 84 | 36 | 10 Jul 2026 | 20 Jul 2026 | Leave | 7 |
| 85 | 10 | 13 Jul 2026 | 15 Jul 2026 | Leave | 3 |
| 86 | 11 | 21 Jul 2026 | 24 Jul 2026 | Sick | 4 |
| 87 | 20 | 21 Jul 2026 | 23 Jul 2026 | Sick | 3 |
| 88 | 5 | 22 Jul 2026 | 24 Jul 2026 | Sick | 3 |
| 89 | 38 | 22 Jul 2026 | 23 Jul 2026 | Sick | 2 |
| 90 | 25 | 27 Jul 2026 | 3 Aug 2026 | Leave | 6 |
| 91 | 23 | 28 Jul 2026 | 10 Aug 2026 | Leave | 10 |
| 92 | 17 | 29 Jul 2026 | 31 Jul 2026 | Sick | 3 |
| 93 | 29 | 31 Jul 2026 | 7 Aug 2026 | Leave | 6 |
| 94 | 9 | 3 Aug 2026 | 6 Aug 2026 | Sick | 4 |
| 95 | 6 | 5 Aug 2026 | 10 Aug 2026 | Leave | 4 |
| 96 | 10 | 6 Aug 2026 | 11 Aug 2026 | Leave | 4 |
| 97 | 36 | 10 Aug 2026 | 21 Aug 2026 | Leave | 10 |
| 98 | 39 | 10 Aug 2026 | 12 Aug 2026 | Sick | 3 |
| 99 | 35 | 12 Aug 2026 | 12 Aug 2026 | Sick | 1 |
| 100 | 40 | 17 Aug 2026 | 20 Aug 2026 | Leave | 4 |
| 101 | 28 | 18 Aug 2026 | 19 Aug 2026 | Sick | 2 |
| 102 | 14 | 25 Aug 2026 | 26 Aug 2026 | Leave | 2 |
| 103 | 4 | 27 Aug 2026 | 28 Aug 2026 | Leave | 2 |
| 104 | 28 | 28 Aug 2026 | 7 Sep 2026 | Leave | 7 |
| 105 | 38 | 1 Sep 2026 | 4 Sep 2026 | Leave | 4 |
| 106 | 18 | 2 Sep 2026 | 8 Sep 2026 | Leave | 5 |
| 107 | 30 | 8 Sep 2026 | 15 Sep 2026 | Leave | 6 |
| 108 | 37 | 10 Sep 2026 | 23 Sep 2026 | Leave | 10 |
| 109 | 18 | 14 Sep 2026 | 18 Sep 2026 | Leave | 5 |
| 110 | 28 | 14 Sep 2026 | 15 Sep 2026 | Sick | 2 |
| 111 | 16 | 18 Sep 2026 | 29 Sep 2026 | Leave | 8 |
| 112 | 33 | 18 Sep 2026 | 22 Sep 2026 | Leave | 3 |
| 113 | 21 | 21 Sep 2026 | 22 Sep 2026 | Leave | 2 |
| 114 | 33 | 30 Sep 2026 | 9 Oct 2026 | Leave | 8 |
| 115 | 24 | 1 Oct 2026 | 12 Oct 2026 | Leave | 8 |
| 116 | 11 | 5 Oct 2026 | 13 Oct 2026 | Leave | 7 |
| 117 | 34 | 5 Oct 2026 | 15 Oct 2026 | Leave | 9 |
| 118 | 30 | 9 Oct 2026 | 21 Oct 2026 | Leave | 9 |
| 119 | 7 | 12 Oct 2026 | 16 Oct 2026 | Sick | 5 |
| 120 | 24 | 15 Oct 2026 | 27 Oct 2026 | Leave | 9 |
| 121 | 25 | 15 Oct 2026 | 21 Oct 2026 | Leave | 5 |
| 122 | 1 | 16 Oct 2026 | 20 Oct 2026 | Leave | 3 |
| 123 | 37 | 16 Oct 2026 | 22 Oct 2026 | Sick | 5 |
| 124 | 11 | 19 Oct 2026 | 29 Oct 2026 | Leave | 9 |
| 125 | 16 | 19 Oct 2026 | 28 Oct 2026 | Leave | 8 |
| 126 | 17 | 20 Oct 2026 | 26 Oct 2026 | Sick | 5 |
| 127 | 2 | 22 Oct 2026 | 23 Oct 2026 | Leave | 2 |
| 128 | 37 | 23 Oct 2026 | 30 Oct 2026 | Leave | 6 |
| 129 | 35 | 27 Oct 2026 | 4 Nov 2026 | Leave | 7 |
| 130 | 26 | 28 Oct 2026 | 29 Oct 2026 | Leave | 2 |
| 131 | 6 | 3 Nov 2026 | 9 Nov 2026 | Sick | 5 |
| 132 | 13 | 9 Nov 2026 | 10 Nov 2026 | Leave | 2 |
| 133 | 26 | 10 Nov 2026 | 23 Nov 2026 | Leave | 10 |
| 134 | 25 | 11 Nov 2026 | 13 Nov 2026 | Sick | 3 |
| 135 | 29 | 11 Nov 2026 | 17 Nov 2026 | Sick | 5 |
| 136 | 34 | 11 Nov 2026 | 16 Nov 2026 | Sick | 4 |
| 137 | 14 | 16 Nov 2026 | 24 Nov 2026 | Leave | 7 |
| 138 | 20 | 16 Nov 2026 | 16 Nov 2026 | Sick | 1 |
| 139 | 35 | 16 Nov 2026 | 23 Nov 2026 | Leave | 6 |
| 140 | 32 | 17 Nov 2026 | 23 Nov 2026 | Sick | 5 |
| 141 | 21 | 18 Nov 2026 | 25 Nov 2026 | Leave | 6 |
| 142 | 11 | 23 Nov 2026 | 27 Nov 2026 | Leave | 5 |
| 143 | 12 | 23 Nov 2026 | 23 Nov 2026 | Sick | 1 |
| 144 | 15 | 23 Nov 2026 | 24 Nov 2026 | Leave | 2 |
This exercise is part of Premium.
Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.
See Premium Already Premium? Log in
The first exercise in this lesson is free.
The lesson on VBA in Access also covers events with Cancel, the lesson on DLookup and DSum domain functions.
Common mistakes
Former employees added too
Without TermDate Is Null, former employees get a record dated 1 Dec 2026 as well. Nobody notices until the next audit.
Message without Cancel
Without Cancel = True the procedure shows the message but saves the request anyway. Anyone who clicks OK quickly has booked too much leave.
In real Access
- In real use, department and training come from combo boxes on a small form; the procedure reads them with Me!cboDepartment.
- When an existing request is edited, DSum already counts its own days. Exclude the current record in the criterion: AND AbsenceID <> Me!AbsenceID.
- A leave check with public holidays and half days needs a table of working days; the logic stays the same.
How to check your result
- Task 1: the message reads “7 records added”, one per active employee in the warehouse.
- Task 2: for employee 6 with 2 days left, “Only 2 days of leave left.” appears and the 5-day request is not saved.
Back to the course overview.