Results 1 to 3 of 3
  1. #1
    cbrxxrider is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Location
    Central NY
    Posts
    16

    Question Query based on txtdept/some txtdepts need to see multiple depts results

    I have a table listing all the departments and a home form with a [txtdept] control.

    I have many different queries pulling information based on the logged in dept. One example is below.

    (weeklycompletions)

    SELECT qryEmployeeWeeklyCompletions.EmployeeID, qryEmployeeWeeklyCompletions.Department, qryEmployeeWeeklyCompletions.[Last Week], qryEmployeeWeeklyCompletions.[This Week], qryEmployeeWeeklyCompletions.[Total Entries]
    FROM qryEmployeeWeeklyCompletions
    WHERE (((qryEmployeeWeeklyCompletions.Department)=[forms]![Home]![txtdept]));



    --

    Some departments oversee other departments. Instead of creating this query many times, I'm wondering if there's criteria I can put in so if the txtdept = Finance, I can make it show finance and receiving, or if it's hotel, it will show hotel and housekeeping.

    I know I could just ask for user input on what department their looking for but I'm trying to keep them from seeing the other depts if I can.

    --

    Another example of my issue is this query showing total completions per department, most depts can use the following...

    SELECT tblCompletions.ID, tblCompletions.Department, [Employees Extended].[Employee Name], tblCompletions.Goal, tblCompletions.CompletionDate AS [Completion Date], [Employees Extended_1].[Employee Name] AS Entered, tblCompletions.[Verified By], tblCompletions.[Verified Date], tblCompletions.Comments, tblCompletions.[Points Earned], tblCompletions.[Denied By], tblCompletions.[Denied Reason], tblCompletions.[Denied Date]
    FROM (tblCompletions INNER JOIN [Employees Extended] ON tblCompletions.EmployeeID = [Employees Extended].UserID) INNER JOIN [Employees Extended] AS [Employees Extended_1] ON tblCompletions.[Entered By] = [Employees Extended_1].UserID
    WHERE (((tblCompletions.Department)=[forms]![Home]![txtdept]) AND ((tblCompletions.[Denied By]) Is Null));

    But since hotel needs to be able to update both hotel and housekeeping I had to create another specifically for them...

    SELECT tblCompletions.ID, tblCompletions.Department, [Employees Extended].[Employee Name], tblCompletions.Goal, tblCompletions.CompletionDate AS [Completion Date], [Employees Extended_1].[Employee Name] AS [Entered By], tblCompletions.Comments, tblCompletions.[Denied By], tblCompletions.[Denied Reason], tblCompletions.[Denied Date]
    FROM (tblCompletions INNER JOIN [Employees Extended] ON tblCompletions.EmployeeID = [Employees Extended].UserID) INNER JOIN [Employees Extended] AS [Employees Extended_1] ON tblCompletions.[Entered By] = [Employees Extended_1].UserID
    WHERE (((tblCompletions.Department)="Hotel") AND ((tblCompletions.[Denied By]) Is Not Null)) OR (((tblCompletions.Department)="Housekeeping") AND ((tblCompletions.[Denied By]) Is Not Null))
    ORDER BY tblCompletions.CompletionDate DESC , tblCompletions.[Denied Date] DESC;

    I assume there's a way for me to use these more wisely and say if there's hotel show both these else show only txtdept. I also created an admin query separately to show all departments.

    Thanks for any input.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    Instead of trying to manage filtering within the query, consider building the filter criteria in VBA and applying to the form Filter property. That's my preference. I don't build dynamic queries. I filter forms and reports.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    cbrxxrider is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Location
    Central NY
    Posts
    16
    Quote Originally Posted by June7 View Post
    Instead of trying to manage filtering within the query, consider building the filter criteria in VBA and applying to the form Filter property. That's my preference. I don't build dynamic queries. I filter forms and reports.
    Thanks, that sounds like a good idea. I'll look into it.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 02-02-2014, 07:19 PM
  2. Replies: 5
    Last Post: 05-21-2013, 02:21 PM
  3. Create Message Box based on query results
    By stanley721 in forum Queries
    Replies: 7
    Last Post: 02-14-2013, 10:04 AM
  4. Replies: 1
    Last Post: 02-04-2012, 02:07 AM
  5. Open form based on query results
    By RobbertH in forum Queries
    Replies: 1
    Last Post: 02-10-2010, 08:13 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums