Results 1 to 2 of 2
  1. #1
    ClintonHolder is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Jan 2012
    Posts
    1

    Running different queries within expression based on field value

    I have a points based attendance database that I am trying to enhance with different rules based on if the employee is part time or full time, for instance I am trying to Dsum their points from all occurrences within the last 365 days but if now I am trying to create some sort of IF the "employeestatus" = PT then only dsum from after Jan 1, 2012 since part time employees had a policy change and I don't want to tally points before the 1st of this year. Can anyone help me understand how to change this expression or allow me to convert it to an IF THEN ELSE statement where I can run different queries based on the value of the "employeestatus" field?



    This is what I have in the control source for the text box on a form that totals the employees current points.
    Code:
    =DSum("Points","qryTardy","EmployeeID = " & [txtEmployeeID])
    qryTardy is the query that filters all occurrences in the last 365 days
    I want the ability to run qryTardyPT if the "employeestatus" field = PT

    qryTardy:
    Code:
    SELECT tblEmployeeTardy.EmployeeTardyID, tblEmployeeTardy.Date, tblEmployeeTardy.EmployeeID, tblEmployeeTardy.Hours, tblEmployeeTardy.Minutes, tblEmployeeTardy.Comments, tblEmployeeTardy.Points, tblEmployeeTardy.TardyID
    FROM tblEmployeeTardy
    WHERE (((tblEmployeeTardy.Date)>=Date()-365));

    Sorry if this sounds convoluted, I have a hard enough time wrapping my brain around it asa semi beginner to Access

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Try:

    =DSum("Points","qryTardy","EmployeeID = " & [txtEmployeeID] & IIf([employeestatus]="PT", " AND [datefield]>=#1/1/2012#", ""))
    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.

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

Similar Threads

  1. Running Queries from a form
    By HaYuM in forum Queries
    Replies: 1
    Last Post: 08-23-2013, 03:12 AM
  2. Replies: 11
    Last Post: 07-08-2011, 02:12 PM
  3. Replies: 13
    Last Post: 02-23-2011, 08:38 AM
  4. Running sum in queries
    By sankarkunnath in forum Queries
    Replies: 0
    Last Post: 10-24-2010, 12:26 PM
  5. Running parameter queries from VBA
    By John Southern in forum Programming
    Replies: 6
    Last Post: 03-25-2010, 10:24 AM

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