Whether you perform this in a Form or in a Query will depend on your process. Either will work.
Something like this is usually taken care of at the time the Date is entered or changed. So if you or your users are entering the LastTestDate on a Form, then it could be taken care of by code on the Form or a Data Macro if you are using Access 2010 or newer (a Data Macro is probably the best method). If you are using a routine to bulk import data then a Query is often used to update the field in Bulk.
Now to really throw a wrench into the works, I need to point out that it's rarely a good idea to save data that can be easily calculated. It's a common practice to create a query for this, and in this case an advantage is that if your rules change on how many years to add, you can change just the query and everything continues to work. This is a related article that might shed some light on this concept:
https://bytes.com/topic/access/insig...ble-structures
So, in a Query, you can do something like this:
- SELECT *, IIf([SomeField]=4,DateAdd('yyyy',1,[LastTestDate]),DateAdd('yyyy',2,[LastTestDate])) AS SomeImportantDate FROM SomeTable
To return the original table as well as the calculated field. The same idea would be used to update a table.
In a Form, when saving the date in the table, the code is similar and looks something like this:
- Private Sub LastTestDate_AfterUpdate()
-
If Not Me!LastTestDate Is Null Then
-
If Me!SomeField = 4 Then
-
Me!SomeImportantDate = DateAdd("yyyy", 1, Me!LastTestDate)
-
Else
-
Me!SomeImportantDate = DateAdd("yyyy", 2, Me!LastTestDate)
-
End If
-
End If
-
End Sub