Ok I've got it working now but I have one question. In my tblUsers in the
field Dept I want to put "All" and have this query show all records for
that
specific user that has "all" in the dept field. How do I write that into
my
query?
SELECT tblEmployees.ID, tblEmployees.LastName, tblEmployees.FirstName,
tblEmployees.LastName & ", " & tblEmployees.FirstName AS LastFirst,
tblEmployees.FirstName & " " & tblEmployees.LastName AS FirstLast,
tblEmployees.EEID, tblEmployees.Dept, tblEmployees.StartDate,
tblEmployees.EndDate, tblEmployees.Address1, tblEmployees.Address2,
tblEmployees.City, tblEmployees.State, tblEmployees.ZipCode,
tblEmployees.HomePhone, tblEmployees.SSN, tblEmployees.Birthdate,
tblEmployees.Status, tblEmployees.Position, tblEmployees.Notes,
DateDiff("m",[StartDate],Date()) AS Accrual,
tblEmployees.memProperyPhotoLink, tblEmployees.VacationOverrides,
tblEmployees.VacationOverrideReason, tblEmployees.BadgeNo,
tblEmployees.Shift, tblEmployees.VacationCarryover,
tblEmployees.VacationCarryoverReason, tblEmployees.NextReviewDate,
tblEmployees.PersonalTimeOverride, tblEmployees.PersonalTimeOverrideReason
FROM tblEmployees
WHERE (((tblEmployees.Dept)=(Select([Dept]) FROM tblUsers WHERE
CurrentUser() = tblUsers.UserName)) AND ((tblEmployees.Status)="Active"))
OR
(((tblEmployees.Dept)=(Select([Dept]) FROM tblUsers WHERE CurrentUser() =
tblUsers.UserName)) AND (([Forms]![frmEmployeeMain]![chkInactive])=-1));
Jeff Boyce said:
You don't mention how these are 'linked', so I'll assume you mean your
tables have foreign key fields that point back at their "parents"
records.
By the way, I'll also assume you don't have any "mesh" or "shared"
assignments, in which a single Employee answers to more than one
Department.
You are asking a "how" question ... how depends on what ... it all starts
with the data. And I'm guessing you'll need so code/procedures also, not
just "a query to link all this together".
FYI, you can use a dynamically-constructed SQL statement in a procedure
to
serve as a query. I'd probably take an approach like this to first
identify
the user logged in, then find the records in tblEmployees who are in that
department.
You could try your hand at creating a query that lists all Employees for
each Department, for each User. Then the only other piece of the puzzle
would be creating the WHERE statement for which User.
Good Luck!
Regards
Jeff Boyce
Microsoft Office/Access MVP