Results 1 to 4 of 4
  1. #1
    balajigade is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Mar 2014
    Posts
    30

    Nested IF

    I have a database of employees in & out punching to the office. The fields are Date, EmpCode, Intime, Outtime, Comments. I want generate a query for the field " Comments" as follows :



    IF intime = null AND outtime = null, Comments = "Absent"
    IF intime = null AND outtime = "", Comments = "Late"
    IF intime = "" AND outtime = null, Comments = "Left Early"
    IF intime = "" AND outtime - "", Comments = "Present"

    I tried various combinations of IIF, OR, AND functions but without any success. The intime & outtime values are in time format, hr:mm

    Pl suggest a solution

    Thanx

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Can't test for = Null http://allenbrowne.com/casu-12.html

    intime and outtime are text type fields? Why would the fields have empty string? Is empty string set as a DefaultValue for textboxes? I never allow empty string in text fields.

    Switch(IsNull(intime) AND IsNull(outtime), "Absent", IsNull(intime) AND outtime="", "Late", intime="" AND IsNull(outtime), "Left Early", intime="" AND outtime="", "Present")
    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
    balajigade is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Mar 2014
    Posts
    30
    The intime & outtime fields are in time format, not as text. I might have made a mistake while denoting the string as " ". The data comes as an excel file which is pasted on to the access table on daily basis. The null values appear when there is no time punch during either checking in or checking out or both, when absent.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    A date/time type field cannot hold an empty string, therefore your conditional code will fail.
    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. nested iif
    By slimjen in forum Reports
    Replies: 1
    Last Post: 03-15-2014, 09:30 AM
  2. Nested DLookup
    By jamarogers in forum Programming
    Replies: 8
    Last Post: 10-13-2013, 12:20 AM
  3. How to end/exit a sub from its nested sub?
    By lookingforK in forum Programming
    Replies: 2
    Last Post: 12-10-2012, 02:13 PM
  4. Nested IIF
    By Oldie in forum Queries
    Replies: 1
    Last Post: 02-17-2012, 06:04 AM
  5. Nested data
    By guichemot in forum Database Design
    Replies: 5
    Last Post: 01-17-2011, 01:20 PM

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