Results 1 to 9 of 9
  1. #1
    datachick is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2014
    Posts
    5

    Issues with IIF Statement

    I am having issues with this IIF statement below in Access 2010:


    this is the ordering of the IIf so that they will be assigned in that order; however, the problem is that I get a #Error when i try this IIf statement.
    The tables are joined on Field A


    Value: IIf([[Table1].[FieldA]in("89812","83849","83847"),"a",
    IIf([[Table1].[FieldA]="91245","a",
    IIf([[Table1].[FieldB] = "102","b",
    IIf([[Table1].[FieldA]="91164","c",
    IIf([[Table1].[FieldA]="39649","d",
    IIf([Table2].[FieldC]="f","f","e"))))))))

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    don use IIF,
    use table to 'translate' these values

    [Field],[value]
    91245 a
    102 , b

    etc... this table in the query will give you the value without IFs and complex sql.

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Numerous syntax errors.

    1 - Why do you have [[ (double opening square brackets) before Table1? There is no need for them, and they result in unbalenced [] pairs.
    2 - Your () pairs are not balanced - you have 8 closing ) when you should only have 6.

    If the values for FieldA and FieldB in Table1 are numeric type, you should not have quotation marks around the values in the Iif expression.
    Last edited by John_G; 08-05-2015 at 10:09 AM. Reason: additional information

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    no, theres no need for them, but it just helps define a field.

  5. #5
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    It's the double [[ that I was referring to; the single ones are fine and do indeed provide clarity.

    [[Table1].[FieldA] should be [Table1].[FieldA] - only one opening [.

  6. #6
    Mahendra1000 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2013
    Posts
    101
    I would like to go on with John_G,

    I think it is due to the syntax error. The open brackets doesn't paired

  7. #7
    LaughingBull is offline Competent Performer
    Windows 8 Access 2003
    Join Date
    Jul 2015
    Location
    Toledo Ohio
    Posts
    143
    Try Select Case here is the youtube link https://www.youtube.com/watch?v=2P0GWYySu0Q

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,623
    I can't get the IN operator to work in expression.

    Consider:

    Switch(InStr("89812,83849,83847,91245",[FieldA])>0,"a", [FieldB]="102","b", [FieldA]="91164","c", [FieldA]="39649","d", [FeldC]="f","f", True,"e")
    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.

  9. #9
    LaughingBull is offline Competent Performer
    Windows 8 Access 2003
    Join Date
    Jul 2015
    Location
    Toledo Ohio
    Posts
    143
    try this video It seem to do what you are looking for https://www.youtube.com/watch?v=Zx0itIyaDuk

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

Similar Threads

  1. For/Next Control Statement Issues
    By nick404 in forum Programming
    Replies: 4
    Last Post: 07-29-2015, 11:24 AM
  2. Replies: 11
    Last Post: 04-29-2015, 01:38 PM
  3. Check box to if statement issues
    By wlkr.jk in forum Programming
    Replies: 3
    Last Post: 07-30-2014, 05:41 AM
  4. 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
  5. Replies: 7
    Last Post: 08-17-2011, 01: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