MS Access IIF instead of LEFT JOIN

Posted on 2011-10-03
Last Modified: 2013-11-27

I've been working on a fairly large SQL query in Access 2007.  I've run into a snag using LEFT JOINs for my lookup tables.  More specifically, I've reached the allowable number of JOINS in Access.  

I'd like to try to use an IIF statement to try to workaround it but I'm not sure exactly how to do it correctly.  My goal is to replace my LEFT JOINS for Yes/No values with an IIF statement so I can free up some JOINS for other lookup fields.  

In an attempt to make this work, I placed the following in the "Field:" row of the column in which I'd like Yes or No returned:

MyField: IIF([MyTable].[YesNo1]="2","Yes","No")

This runs but in the returned data I get "#ERROR".  Is this possible?  If so, do you know where I've gone wrong?

Question by:ttist25
    LVL 56

    Expert Comment

    by:Jim Dettman (Microsoft MVP/ EE MVE)
    <<This runs but in the returned data I get "#ERROR".  Is this possible?  If so, do you know where I've gone wrong?>>

      Your syntax is correct, but you most likely have a broken reference.  Open a code module in design view, click tools/references and look for any that are MISSING or BROKEN.

      If none are, check any unchecked reference, then close the DB and Access, re-open and uncheck the reference just checked.  Then compile and save.

     Then try the query.

    LVL 47

    Accepted Solution

    Or it could be that the field is numeric, not text:

    instead of:

    MyField: IIF([MyTable].[YesNo1]="2","Yes","No")


    MyField: IIF([MyTable].[YesNo1]=2,"Yes","No")

    LVL 1

    Author Closing Comment

    That's what it was.  I figured it out as you were posting it!  Thanks!
    LVL 47

    Expert Comment

    by:Dale Fye (Access MVP)
    So, what is the limit on the number of joins?

    I've written some pretty outrageous queries, but don't think I've ever run into that problem.
    LVL 26

    Expert Comment

    You can create queries of queries.
    It might be much more mainatainable to grab some of your data, save it as a query, and then use that query in another query.
    Queries behave just like tables.

    A huge query with a bazillion IIF([MyTable].[YesNo1]="2","Yes","No")
    will be difficult to maintain
    LVL 33

    Expert Comment

    The maximum no of joins in a query is 16.

    There must be some other way to do this rather than using a whole bunch of Iifs and what sounds like a lot of joins.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
    Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
    What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
    In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now