Can anyone please help me re-write this code more efficiently?
Private Sub RESULTS_AfterUpdate()
DoCmd.RunSQL "UPDATE [EMPLOYEE HEALTH] SET [EMPLOYEE HEALTH].[TB DUE DATE] = " & _
"IIf([TB DUE DATE] > DMax(""[DATE]"", ""EH - TB"", ""[ID]=" & Me![id] & """) Or [TB DUE DATE] Is Null, " & _
"DateAdd(""yyyy"", 1, DMax(""[DATE]"", ""EH - TB"", ""[ID]=" & Me![id] & """)), " & _
"IIf([TB DUE DATE]<DMax(""[DATE]"", ""EH - TB"",""[ID]=" & Me![id] & """), " & _
"DateAdd(""yyyy"",1,[TB DUE DATE]))) WHERE [ID]=" & Me![id] & " AND [TYPE] <> ""CHEST X-RAY"""
End Sub
It works, but how can I simplify it in a module so it is more clear and DMax(""[DATE]"", ""EH - TB"",""[ID]=" & Me![id] & """) is declared once and then referenced throughout the code?
Thanks
Private Sub RESULTS_AfterUpdate()
DoCmd.RunSQL "UPDATE [EMPLOYEE HEALTH] SET [EMPLOYEE HEALTH].[TB DUE DATE] = " & _
"IIf([TB DUE DATE] > DMax(""[DATE]"", ""EH - TB"", ""[ID]=" & Me![id] & """) Or [TB DUE DATE] Is Null, " & _
"DateAdd(""yyyy"", 1, DMax(""[DATE]"", ""EH - TB"", ""[ID]=" & Me![id] & """)), " & _
"IIf([TB DUE DATE]<DMax(""[DATE]"", ""EH - TB"",""[ID]=" & Me![id] & """), " & _
"DateAdd(""yyyy"",1,[TB DUE DATE]))) WHERE [ID]=" & Me![id] & " AND [TYPE] <> ""CHEST X-RAY"""
End Sub
It works, but how can I simplify it in a module so it is more clear and DMax(""[DATE]"", ""EH - TB"",""[ID]=" & Me![id] & """) is declared once and then referenced throughout the code?
Thanks