SELECT tblEmployees.EmpID, tblEmployees.DOB, DateSerial(Year(Date()),Month([DOB]),Day([DOB])) AS DueDate, "Greet Employee Birthday" AS TaskDescription, "Employee Birthday" AS TaskCatagory, IIf([DueDate]="",0,[DueDate]-1) AS ReminderDate
FROM tblEmployees INNER JOIN tblEmploymentContracts ON tblEmployees.EmpID = tblEmploymentContracts.EmployeeID
WHERE (([tblEmploymentContracts]![ContractStatus]="Active") AND ((tblEmployees.DOB)>0))
UNION ALL
SELECT tblEmploymentContracts.EmployeeID, tblEmploymentContracts.HireDate, DateSerial(Year(Date()),Month([HireDate]),Day([HireDate])) AS DueDate, "Congratulate Work Anniversary" AS TaskDescription, "Work Anniversary" AS TaskCatagory, IIf([DueDate]="",0,[DueDate]-1) AS ReminderDate
FROM tblEmploymentContracts
WHERE (([tblEmploymentContracts]![ContractStatus]="Active") AND ((tblEmploymentContracts.HireDate)>0))
UNION ALL
SELECT tblLifeInsurance.EmpID, tblLifeInsurance.EndDate, DateSerial(Year(Date()),Month([EndDate]),Day([EndDate])) AS DueDate, "Life Insurance Renewal" AS TaskDescription, "Life Insurance" AS TaskCatagory, IIf([DueDate]="",0,[DueDate]-30) AS ReminderDate
FROM tblEmploymentContracts INNER JOIN tblLifeInsurance ON tblEmploymentContracts.EmployeeID = tblLifeInsurance.LifeInsurance_ID
WHERE (([tblEmploymentContracts]![ContractStatus]="Active") AND ((tblLifeInsurance.EndDate)>Date()))
UNION ALL
SELECT tblMedical.EmpID, tblMedical.CoverEnd, DateSerial(Year(Date()),Month([CoverEnd]),Day([CoverEnd])) AS DueDate, "Medical Insurance Renewal" AS TaskDescription, "Medical Insurance" AS TaskCatagory, IIf([DueDate]="",0,[DueDate]-15) AS ReminderDate
FROM (tblEmployees INNER JOIN tblEmploymentContracts ON tblEmployees.EmpID = tblEmploymentContracts.EmployeeID) INNER JOIN tblMedical ON tblEmployees.EmpID = tblMedical.EmpID
WHERE (([tblEmploymentContracts]![ContractStatus]="Active") AND ((tblMedical.CoverEnd)>Date()))
UNION ALL
SELECT tblPassports.EmpID, tblPassports.ExpiryDate, DateSerial(Year(Date()),Month([ExpiryDate]),Day([ExpiryDate])) AS DueDate, "Passport Renewal" AS TaskDescription, "Passport" AS TaskCatagory, IIf([DueDate]="",0,[DueDate]-90) AS ReminderDate
FROM (tblEmployees INNER JOIN tblEmploymentContracts ON tblEmployees.EmpID = tblEmploymentContracts.EmployeeID) INNER JOIN tblPassports ON tblEmployees.EmpID = tblPassports.EmpID
WHERE (([tblEmploymentContracts]![ContractStatus]="Active") AND ((tblPassports.ExpiryDate)>Date()))
UNION ALL
SELECT tblPayroll.EmpID, tblPayroll.PayEndDate, DateSerial(Year(Date()),Month([PayEndDate]),Day([PayEndDate])) AS DueDate, "Payroll Preparation" AS TaskDescription, "Payroll" AS TaskCatagory, IIf([DueDate]="",0,[DueDate]-6) AS ReminderDate
FROM (tblEmployees INNER JOIN tblEmploymentContracts ON tblEmployees.EmpID = tblEmploymentContracts.EmployeeID) INNER JOIN tblPayroll ON tblEmployees.EmpID = tblPayroll.EmpID
WHERE (([tblEmploymentContracts]![ContractStatus]="Active") AND ((tblPayroll.PayEndDate)>Date()))
UNION ALL
SELECT tblResidentID.EmpID, tblResidentID.ExpiryDate, DateSerial(Year(Date()),Month([ExpiryDate]),Day([ExpiryDate])) AS DueDate, "Resident ID Renewal" AS TaskDescription, "Resident ID" AS TaskCatagory, IIf([DueDate]="",0,[DueDate]-30) AS ReminderDate
FROM (tblEmployees INNER JOIN tblEmploymentContracts ON tblEmployees.EmpID = tblEmploymentContracts.EmployeeID) INNER JOIN tblResidentID ON tblEmployees.EmpID = tblResidentID.EmpID
WHERE (([tblEmploymentContracts]![ContractStatus]="Active") AND ((tblResidentID.ExpiryDate)>Date()))
UNION ALL SELECT tblSocialinsurance.EmpID, tblSocialinsurance.EndDate, DateSerial(Year(Date()),Month([EndDate]),Day([EndDate])) AS DueDate, "Social Insurance Renewal" AS TaskDescription, "Social Insurance" AS TaskCatagory, IIf([DueDate]="",0,[DueDate]-8) AS ReminderDate
FROM (tblEmployees INNER JOIN tblEmploymentContracts ON tblEmployees.EmpID = tblEmploymentContracts.EmployeeID) INNER JOIN tblSocialinsurance ON tblEmployees.EmpID = tblSocialinsurance.EmpID
WHERE (([tblEmploymentContracts]![ContractStatus]="Active") AND ((tblSocialinsurance.EndDate)>Date()))
UNION ALL
SELECT tblTax.EmpID, tblTax.PeriodTo, DateSerial(Year(Date()),Month([PeriodTo]),Day([PeriodTo])) AS DueDate, "Tax Payment" AS TaskDescription, "Tax" AS TaskCatagory, IIf([DueDate]="",0,[DueDate]-30) AS ReminderDate
FROM (tblEmployees INNER JOIN tblEmploymentContracts ON tblEmployees.EmpID = tblEmploymentContracts.EmployeeID) INNER JOIN tblTax ON tblEmployees.EmpID = tblTax.EmpID
WHERE (([tblEmploymentContracts]![ContractStatus]="Active") AND ((tblTax.PeriodTo)>Date()))
UNION ALL
SELECT tblTraining.EmpID, tblTraining.EndDate, DateSerial(Year(Date()),Month([EndDate]),Day([EndDate])) AS DueDate, "Training Status Update" AS TaskDescription, "Employee Training" AS TaskCatagory, IIf([DueDate]="",0,[DueDate]-3) AS ReminderDate
FROM (tblEmployees INNER JOIN tblEmploymentContracts ON tblEmployees.EmpID = tblEmploymentContracts.EmployeeID) INNER JOIN tblTraining ON tblEmployees.EmpID = tblTraining.EmpID
WHERE (([tblEmploymentContracts]![ContractStatus]="Active") AND ((tblTraining.EndDate)>Date()))
UNION ALL
SELECT tblTravelInsurance.EmpID, tblTravelInsurance.CoverageEnd, DateSerial(Year(Date()),Month([CoverageEnd]),Day([CoverageEnd])) AS DueDate, "Travel Insurance Status Update" AS TaskDescription, "Travel Insurance" AS TaskCatagory, IIf([DueDate]="",0,[DueDate]-4) AS ReminderDate
FROM (tblEmployees INNER JOIN tblEmploymentContracts ON tblEmployees.EmpID = tblEmploymentContracts.EmployeeID) INNER JOIN tblTravelInsurance ON tblEmployees.EmpID = tblTravelInsurance.EmpID
WHERE (([tblEmploymentContracts]![ContractStatus]="Active") AND ((tblTravelInsurance.CoverageEnd)>Date()))
UNION ALL SELECT tblVisas.EmpID, tblVisas.ExpiryDate, DateSerial(Year(Date()),Month([ExpiryDate]),Day([ExpiryDate])) AS DueDate, "Visa Status Update" AS TaskDescription, "Visa" AS TaskCatagory, IIf([DueDate]="",0,[DueDate]-5) AS ReminderDate
FROM (tblEmployees INNER JOIN tblVisas ON tblEmployees.EmpID = tblVisas.EmpID) INNER JOIN tblEmploymentContracts ON tblEmployees.EmpID = tblEmploymentContracts.EmployeeID
WHERE (([tblEmploymentContracts]![ContractStatus]="Active") AND ((tblVisas.ExpiryDate)>Date()));