Bert said:
I use a query to keep track of sick days. The query only keeps the days
that are less than a year old, which I want. The problem I have is that when
somebody does not call in sick for 6 months, his sick days need to be reset
to 0. This is the part where I need help. The query will return the sick
days that are less than a year old. However, when the last sick day is more
than 6 months old from today, I do not want the query to return the sick
days. In that instance I want the query to give me only the days that are
less than 6 months old. I created a date field, Expr1, with a date that is 6
months ago from today. I tried to use the criteria >Between [Expr1] and
Date() is null, which didn't work. Can somebody help me?
old I created a date field with a date of six month ago as of the current
date. I was wrong by thinking that the Between function would work.
Hmmm, if I understand correctly, you want the Query to return only a total
of all sick leave dates that are less than six months old?
CREATE TABLE Employees
(EmployeeID INTEGER
,TotalSickDays BYTE
,CONSTRAINT pk_Employees PRIMARY KEY (EmployeeID)
)
Sample Data
1, 3
2, 0
3, 1
CREATE TABLE SickDates
(EmployeeID INTEGER
,SickDate DATE
,CONSTRAINT pk_SickDates PRIMARY KEY (EmployeeID, SickDate)
,CONSTRAINT fk_SickDates_Employess FOREIGN KEY (EmployeeID)
REFERENCES Employees (EmployeeID)
)
Sample Data
1, 09/01/03
1, 02/01/04
1, 03/01/04
2, 03/16/04
3, 09/15/03
SELECT S1.EmployeeID
,COUNT(S1.SickDate) As TotalSickDays
FROM SickDates AS S1
WHERE (S1.SickDate > (DateSerial(Year(Date()), Month(Date()) - 6,
Day(Date()))
GROUP BY S1.EmployeeID
Should Return the quantity of all Sickdates since a date six months ago.
From the context of the description above, it sounds like there is a total
Sick Days column somewhere, possibly in the Employee Table (I'm not sure,
either way). But it is mentioned that "sick days need to be reset to 0".
Trying to use the above query (even including tricks to preseve the
indication of zero quantity of sick days) as a source in an Update Query
will fail, because there is Aggregation, and Access will throw its
ripping-out-hair-at-the-roots "Operation Must use an Updateable query"
error.
This query will have to be translated into a Make-Table Query, the new
table (strangely updateable with excactly the same information) will have to
be used to update any Total of Sick days in another table, and then the
temporary table will have to be deleted. This can be handled as a Macro,
but would be better off controlled from VBA.
Sincerely,
Chris O.