Results 1 to 4 of 4
  1. #1
    mitchmcc is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Location
    St. Petersburg, FL
    Posts
    19

    using a nested select as "true condition" for IIF

    I cannot get a nested select statement to work as the "true" condition of an IIF statement, e.g.


    Code:
    SELECT [Certification List].ID, 
    [Certification List].Certification, 
    [Group List].Group, 
    [Group List].ID 
    FROM [Group List] 
    INNER JOIN ([Certification List] 
    INNER JOIN [Group Certifications] ON [Certification List].ID=[Group Certifications].Certification_Id) 
    ON [Group List].ID=[Group Certifications].Group_Id 
    WHERE ([Group List].ID=IIf(IsNull(forms.[Employee Certification Tracking].txtGroupCertsGroupId),(SELECT Min([Group List].ID) AS MinOfID FROM [Group List]),CInt(forms.[Employee Certification Tracking].txtGroupCertsGroupId)));
    When I hard-code the nested select as "3", it works fine.

    Does anyone know if this *should* work?

    Thanks,

    Mitch

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    What goes wrong - error message, wrong results, nothing?

    I don't think an IIf in WHERE will work. My attempts always fail. Create a new field with expression that will return True or False then set the criteria for that field to whichever you want.
    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.

  3. #3
    mitchmcc is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Location
    St. Petersburg, FL
    Posts
    19
    The Iff worked fine for me, with a hard-coded "true" condition... but using the nested select did not.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Wow, it does work! I guess I just always gave up on IIf in criteria or I have forgotten where I succeeded.

    I also got a SELECT in the criteria to work.

    I can't see anything wrong with your query. I would have to test with data if you want to provide.
    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.

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

Similar Threads

  1. Replies: 16
    Last Post: 11-01-2011, 01:35 PM
  2. Replies: 16
    Last Post: 07-22-2011, 09:23 AM
  3. ComboBox "Select" and "DLookUp"
    By witooldas in forum Forms
    Replies: 0
    Last Post: 03-23-2011, 03:31 AM
  4. True, "Wahr" and -1 / 0
    By asearle in forum Programming
    Replies: 5
    Last Post: 08-24-2010, 12:09 PM
  5. Replies: 2
    Last Post: 08-31-2006, 12:19 PM

Tags for this Thread

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