Results 1 to 4 of 4
  1. #1
    jferguson is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2012
    Posts
    1

    Trying to use IIF and AND together but getting an error

    Hello All. I am trying to use the following, but the result is "Error" in the field instead of the number of days:

    Code:
    daysToFirstPmt2: IIf([Date Closed]<>"" And [First Payment Date]="","1000",IIf([Date Closed]="" And [First Payment Date]="",Date()-[Date Entered],[First Payment Date]-[Date Entered]))
    Any help would be greatly appreciated.

    Thanks,
    J

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    You may get more responses if you describe WHAT you are trying to do in plain English -- not a quasi expression.

    You are dealing with Date data types so you should look at the various Date related functions.

    There are function definitions and samples at http://www.techonthenet.com/access/functions/index.php
    Look art the date functions.

    I suggest you research Naming Convention and not use spaces and special characters in field and object names.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Why are you testing for empty string? Is it possible for any of those fields to be Null?
    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.

  4. #4
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    I see two possible issues -

    First, you want the number of days, so in this bit :

    IIf([Date Closed]<>"" And [First Payment Date]="","1000".... , the 1000 should not be in quotes.

    Second, in this bit:

    IIf([Date Closed]="" And [First Payment Date]="",Date()-[Date Entered],[First Payment Date]-[Date Entered]))

    If [date closed] is NOT = "", but [First Payment Date] IS = "", then what is [First Payment Date]-[Date Entered] ,
    because that is what the IIF will give you.

    One caveat worth mentioning: As I recall, the IIF evaluates ALL expressions in it, regardless of the conditions,
    so if any of the expressions generates an error, the IIF will fail.

    This is an important difference between an IIF and an If - Then - Else - Endif construct.

    Also, as June7 has pointed out, you should consider the possibility that your fields
    are Null, instead of "" - they are not the same.

    HTH

    John

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

Similar Threads

  1. Replies: 0
    Last Post: 07-16-2012, 05:42 AM
  2. Replies: 7
    Last Post: 06-08-2012, 09:55 PM
  3. Replies: 6
    Last Post: 05-30-2012, 12:32 PM
  4. Replies: 1
    Last Post: 05-11-2012, 10:59 AM
  5. Replies: 5
    Last Post: 03-27-2012, 01:40 PM

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