1. Create a query using your table.
2. Depress the Total button on the toolbar.
Access adds a Total row to the grid.
3. Drag EmpID into the grid.
Accept Group By in the Total row.
4. Drag Action into the grid.
In the Total row under this field, choose Where.
In the Criteria row under this field, enter:
"HIR" or "REH"
so it restricts the query to only hiring dates.
5. Drag the EffDate field into the grid.
In the Total row, choose Max.
The query now shows 1 row for each employee, with their most recent hire or
rehire date.
6. Type this expression into a fresh column in the Field row, and choose
Expression in the Group By row:
(SELECT Min(EffDate) FROM Table1 AS Dupe
WHERE (Dupe.Action = "TER")
AND (Dupe.EffDate > MaxOfEffDate)
AND (Dupe.EmpID = Table1.EmpID))
The new column should give you the first termination date for the person
after their most recent hire/rehire date. If it won't play ball, save the
query at step 5. Then create a new query using the other one as an input
"table", and try the expression again.
7. Once you have that working, you can calculate the difference in years.
Presumably you want to use today's date if the employeement is still
current, so that is:
Nz((SELECT Min(EffDate) FROM Table1 AS Dupe
WHERE (Dupe.Action = "TER")
AND (Dupe.EffDate > MaxOfEffDate)
AND (Dupe.EmpID = Table1.EmpID)),Date())
Now for the difference in years, use something like:
Age(MaxOfEffDate,
Nz((SELECT Min(EffDate) FROM Table1 AS Dupe
WHERE (Dupe.Action = "TER")
AND (Dupe.EffDate > MaxOfEffDate)
AND (Dupe.EmpID = Table1.EmpID)),Date()))
grabbing the Age() function from:
http://allenbrowne.com/func-08.html