I tried this as you suggested. the query takes about 30 seconds to run,
then there is no result. Heres what I have now.
SELECT tblDate.theDate, EMP.EID
FROM tblDate, EMP
WHERE ((((SELECT IDRa_ID FROM IDRa
WHERE IDRa.EID = EMP.EID
AND IDRa.Current_Date = tblDate.theDate))=False));
The cartesian product needs to be on every combination of date and
employee.
Try:
SELECT tblDate.theDate, EMP.EID
FROM tblDate, EMP
WHERE ...
Allen, I tried your suggestion below but I come up with no result in
the query. Here is a copy of the sql statement. "IDRa" is the
timesheet tbl, primary key is "IDRa_ID". The employee tbl is "EMP"
where all the employees and employee id numbers [EID] are listed.
Thanks for your help...Randy
SELECT tblDate.theDate
FROM tblDate, IDRa
WHERE NOT EXIST (SELECT IDRa_ID FROM IDRa
WHERE IDRa.EID = EMP.EID
AND IDRa.Current_Date = tblDate.TheDate);
Randy, the missing dates have to come from somewhere, so you need a
table of all dates.
If you already have a roster of who should be on when, that would
work. Or you could create a table of all dates, and then possibly
remove the public holidays when noone works.
You can then create a query that:
- Selects all dates from this table in the date range.
- Includes the Employee table (no join, i.e. a cartesian product.)
- Uses a subquery to finds the timesheets that don't exist for the
employee + date
The WHERE clause of your query will include this kind of thing:
WHERE NOT EXIST (SELECT TimesheeID FROM tblTimeSheet
WHERE tblTimesheet.EmployeeID = tblEmployee.EmployeeID
AND tblTimesheet.WorkDate = tblDate.TheDate)
If subqueries are new, Microsoft has an introductory article:
How to Create and Use Subqueries
at:
http://support.microsoft.com/?id=209066
If you need to programmatically fill a table with dates, create a
table named (say) "tblDate", with one date/time field named "theDate"
as primary key. Then you can add 10 years of dates like this:
Function MakeDates()
Dim dt As Date
Dim rs As DAO.Recordset
Set rs = DBEngine(0)(0).OpenRecordset("tblDate")
With rs
For dt = #1/1/2005# To #12/31/2014#
.AddNew
!TheDate = dt
.Update
Next
End With
rs.Close
Set rs = Nothing
End Function
Access 2000. I have an employee db. where employee timesheets are
entered. I need a query that will return missing dates or if a
timesheet from a particular date that is missing. I have a field
for entering the date [Currrent_date] and a field where I enter
[CID] "First Day" and "Last Day" This is the employees first day and
last day in this office. What is the best approach...Thanks..Randy