Results 1 to 10 of 10
  1. #1
    mohiahmed is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2012
    Posts
    23

    IIF issue

    Hi everyone,



    I am trying to add a calculated field by using the below code:

    IIf([Post Code]=E11,5,IIf([Post Code]=E10,15))

    I keep getting a syntax error - can anyone help?

    Thank you

  2. #2
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529

  3. #3
    mohiahmed is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2012
    Posts
    23
    Thank you,

    What about if there were more than one condition? I.e. More than one post code?

  4. #4
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    If there is more than one condition, then you need to nest your iif statment.

    Here is the syntax:

    =IIf(firstCriteria, TrueValue for first, IIf(SecondCriteria, TrueValue for Second, False Value for both))

    You can add additional IIFs in the False Value, but the last value must be the false for all. If you have more than seven nests (I believe) you should then switch to VBA and use IF-THEN or Case Select.

    You can google these items for further explanation

  5. #5
    mohiahmed is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2012
    Posts
    23
    I will try it out but I thought I was using nested iif statement

  6. #6
    mohiahmed is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2012
    Posts
    23
    Thank you...I tried this:

    =IIf([Post Code], E18, 10, IIf([Post Code], E17, 5, IIf([Post Code], E16, 5, 0))

    What I wanted is if the value for postcode is E18 then 10 should appear, if it is E17 then 5 should appear, if it is E16 then 5 should also appear and if none of the three postcodes then 0 should appear.

    I get a "Wrong number of arguments" error? What am I doing wrong?

  7. #7
    mohiahmed is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2012
    Posts
    23
    ...I finally got it to work!

    Thank you very much Alan!

    Now my biggest problem....new thread time!

  8. #8
    mohiahmed is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2012
    Posts
    23
    ...Ahh!! It was working but now all that appears in the field is "#error"?

    This is the code I was using and it worked but now it doesn't?

    Sib P: IIf([Number of Sibling(s)]="1","15",IIf([Number of Sibling(s)]="2","25",IIf([Number of Sibling(s)]>"2","30","0")))

  9. #9
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by mohiahmed View Post
    ...Ahh!! It was working but now all that appears in the field is "#error"?

    This is the code I was using and it worked but now it doesn't?

    Sib P: IIf([Number of Sibling(s)]="1","15",IIf([Number of Sibling(s)]="2","25",IIf([Number of Sibling(s)]>"2","30","0")))

    Why are ther quotes around the numbers? Is [Number of Sibling(s)] a text field?
    If it is not a string (text), you should use:

    Sib P: IIf([Number of Sibling(s)]= 1, 15, IIf([Number of Sibling(s)]= 2, 25, IIf([Number of Sibling(s)]> 2, 30, 0)))
    2 is numeric
    "2" is a string
    therefore
    "2" <> 2

    BTW, you shouldn't use spaces or special characters in object names....

  10. #10
    mohiahmed is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2012
    Posts
    23
    Thank you, it works fine now!

    SSAnFu do you have any idea how to solve the issue I am having in my other thread?

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

Similar Threads

  1. Very Critical Issue?
    By cap.zadi in forum Forms
    Replies: 15
    Last Post: 09-11-2011, 01:02 PM
  2. VBA Issue
    By MikeDBMan in forum Access
    Replies: 9
    Last Post: 08-02-2011, 03:59 PM
  3. VBA Issue with Command
    By daversb in forum Programming
    Replies: 7
    Last Post: 05-27-2011, 01:36 PM
  4. Issue with Do
    By Petefured in forum Programming
    Replies: 1
    Last Post: 05-25-2011, 09:27 AM
  5. Issue with Relationships
    By Ev0luTioN in forum Database Design
    Replies: 5
    Last Post: 08-06-2010, 11:45 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