Results 1 to 15 of 15
  1. #1
    Rhubie is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    85

    IIf statement

    I have this expression



    IIf(Mid([WBCode],4,1)="D",([WBCost]+[WBShipping])*[ExchangeRate],[WBCost]*[ExchangeRate])

    I need to add another IIf statement and I am not sure how to add it -

    I have have another statement that says IIf(Mid([WBCode, 4,1)="W", ([WBCost]+1% of WBCost......

    Do I use a or IIf? I want it to do what is is doing for D, and something else for W

  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,850
    IIf(Mid([WBCode, 4,1)="W", ([WBCost]+1% of WBCost......

    Fir an IIF statement ,you need a value if the condition is True, and a value if the condition is False

    IIf (condition, True, False)

    so what are the TRUE and FALSE values?

    And what does this mean in plain English?

    ([WBCost]+1% of WBCost......

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    It is easier to start out with just the IIF() syntax, then add the conditions and expressions. It sounds like you want to use 2 nested IIF() statements. So start with:
    Code:
    IIF(condition, TRUE, FALSE)
    Then add the second IIF():
    Code:
    IIF(condition, TRUE, IIF(condition, TRUE, FALSE))
    Now add the condition for the first (outer) IIF():
    Code:
    IIF(Mid([WBCode],4,1)="D", TRUE, IIF(condition, TRUE, FALSE))
    then the TRUE part:
    Code:
    IIF(Mid([WBCode],4,1)="D", ([WBCost]+[WBShipping])*[ExchangeRate],[WBCost]*[ExchangeRate]), IIF(condition, TRUE, FALSE))
    the FALSE part is the nested IIF() function , so
    now add the condition for the inner IIF(), then the TRUE clause and the FALSE clause:
    Code:
    IIF(Mid([WBCode],4,1)="D", ([WBCost]+[WBShipping])*[ExchangeRate],[WBCost]*[ExchangeRate]), IIF(condition, TRUE, FALSE))

  4. #4
    Rhubie is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    85
    I have the if statment working for if the letter is D do this, but if the letter is W do something else - how do I add the second part of it.

    Should I be using something other than an IIF statement

  5. #5
    Rhubie is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    85
    I actually have three things that I am looking for

    If D do this
    If W do this
    If anything else do this

  6. #6
    Rhubie is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    85
    I'm missing something - and I'm not sure what?

    IIF(Mid([WBCode],4,1)="D", ([WBCost]+[WBShipping])*[ExchangeRate],[WBCost]*[ExchangeRate]), IIF(Mid([WBCode],4,1)-“W”,([WBCost]+([WBCost]*.01)*[ExchangeRate],[WBCost]*[ExchangeRate]))

  7. #7
    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,850
    IIF(Mid([WBCode],4,1)="D",([WBCost]+[WBShipping])*[ExchangeRate],IIF(Mid([WBCode],4,1)=“W”,([WBCost]*1.01)*[ExchangeRate],[WBCost]*[ExchangeRate]))
    .......condition.................... ----------------TRUE-------------------::::::::::::::::::::::::::::::::::::::FALSE::::::: ::::::::::::::::::::::::::::::::::::::::::::::::::
    .................................................. .................................................. .......Condition2..............True part.................................|......False part................

  8. #8
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,085
    Just to be clear.

    Using regular If then statements

    Code:
    If D Then
        Do this
    Else
        If W Then
             Do This
        Else
             Do This
        End if
    End if
    Assuming that's what you want then look at Steve's message above.

    If we break down your IIF Statement

    IIF(Mid([WBCode],4,1)="D", ([WBCost]+[WBShipping])*[ExchangeRate],[WBCost]*[ExchangeRate]), IIF(Mid([WBCode],4,1)-“W”,([WBCost]+([WBCost]*.01)*[ExchangeRate],[WBCost]*[ExchangeRate]))

    Code:
    IIF(Expression = Mid([WBCode],4,1)="D"
    True part = ([WBCost]+[WBShipping])*[ExchangeRate]
    False part = [WBCost]*[ExchangeRate])
    
    This is where the IIF Statement ends
    
    The rest of this will error
    ,IIF(Mid([WBCode],4,1)-“W”,([WBCost]+([WBCost]*.01)*[ExchangeRate],[WBCost]*[ExchangeRate])) 
    

  9. #9
    Rhubie is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    85
    I'm getting this error

    The expressions you entered contains invalid syntax, or you need to enclose your text data in quotes.

    You may have entered an invalid commoa or omitted quotation marks. For example, if the Default Value property of a text fiels is "Huey, Louie, and Dewey, .....

  10. #10
    Rhubie is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    85
    Yes the regular If statement is what I want to do - can I do this in an expressions?

  11. #11
    Rhubie is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    85
    is there a way to else?

  12. #12
    Rhubie is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    85
    I guess my questions is - is there a way to do this in Access 2010?

  13. #13
    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,850
    Did you try the expression I gave in post 7?
    I adjusted the statement and syntax to match what you said in post 6.

  14. #14
    Rhubie is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    85
    It is working - thank you so much for your time - this has been very frustrating

  15. #15
    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,850

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

Similar Threads

  1. Replies: 7
    Last Post: 08-17-2011, 01:49 PM
  2. If statement help please
    By bgeorge12 in forum Programming
    Replies: 12
    Last Post: 06-28-2011, 08:41 PM
  3. for each statement in vba
    By tuyo in forum Access
    Replies: 0
    Last Post: 03-22-2011, 05:42 PM
  4. iff Statement
    By tkandy in forum Access
    Replies: 0
    Last Post: 03-20-2011, 02:31 PM
  5. If Then Statement Help
    By Kapelluschsa in forum Programming
    Replies: 5
    Last Post: 08-11-2010, 09: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