Results 1 to 3 of 3
  1. #1
    Xterra14s is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    May 2016
    Posts
    32

    IIf statement for the following...

    So I'm a little confused on how to go about writing an IIF statement. I am familiar with them and have used them multiple times before but never in this way. I know what I want to do and how to do it in "English words" but not sure how to do it in an expression.
    Here is what I'm trying to do:

    IIF Machine is BiPAP and order date is less than 5 years before today's date then display "Machine is still in warranty"



    I think the date portion would be like this: Date()-1825>=[Order Date]

    I'm not too sure where to even begin with this, any help is greatly appreciated.

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    IIF is an Inline If statement. Since you need to incorporate functions, it may be helpful if you isolate those first. Then, try and incorporate them into your IIF().

    You started that process with trying to get your date sorted out.
    I think the date portion would be like this: Date()-1825>=[Order Date]
    When counting things like days months and years, it is best to use functions that will take into account things like leap years and months with 28 or 30 days. Maybe you can test the following VBA out in a form. Check to see if it is counting the correct number of years.
    Code:
    if DateDiff("yyyy",Me![Order Date],Date()) > 4 Then
    msgbox "Out of warranty"
    end if

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    ir something like

    iif( Machine ='BiPAP' and orderdate>dateadd("yyyy",-5,date()),"Machine is still in warranty","")
    Last edited by CJ_London; 08-17-2016 at 08:12 AM. Reason: used wrong function

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

Similar Threads

  1. Replies: 11
    Last Post: 04-29-2015, 01:38 PM
  2. Help with If Statement
    By zero3ree in forum Access
    Replies: 3
    Last Post: 02-19-2013, 10:19 AM
  3. if statement in sql statement, query builder
    By 54.69.6d.20 in forum Access
    Replies: 4
    Last Post: 09-11-2012, 07:38 AM
  4. Replies: 7
    Last Post: 08-17-2011, 01:49 PM
  5. Need Help with SQL Statement
    By Hank44 in forum Programming
    Replies: 3
    Last Post: 11-08-2010, 05:49 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