Results 1 to 5 of 5
  1. #1
    offie is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    176

    IFF statement messing up query?

    I have a form with checkboxes, each pertaining to a type of project, differentiable by the ProjcetCode
    One type of project is special and can only be found by the Title (starts with "Job Order"), the checkbox for this one is called JCheck.

    I set each checkmark to an IIF statement, so if MCheck is chosen then like "M*"

    I run into problems when I try to find the Job Order Projects.


    I add the field [Title] and add to the criteria:
    IIF([Forms]![Navigation Form]![NavigationSubform].[Form]![NavigationSubform].[Form]![JCheck]=True,Like "Job Order*", Not Like "Job Order*")

    But when I do this it ALL stops working (All the checkboxes, nothing shows up when I run the query/search form)
    I changed the criteria on [Title] to something simple and it worked then so I know it's not a relationship issue

    Did I set it up wrong? Is there some rule I don't know?

    Another thing that I was thinking is that the J projects technically start with 4, some maybe that's confusing something? But I checked both 4 and J and still nothing shows up.

    Help?

    With J Criteria
    Code:
    SELECT COTest2.ProjectCode, COTest2.FiscalYear, COTest2.Quarter, COTest2.SumOfActualAmount AS [Change Order Sum], COTest2.SumOfContractAmount AS [Contract Amount], Round([SumOfActualAmount]/[SumOfContractAmount]*100,2) AS [Percent], dbo_Project.Title
    
    FROM COTest2 INNER JOIN dbo_Project ON COTest2.ProjectCode = dbo_Project.ProjectCode
    
    WHERE 
    (((COTest2.ProjectCode) Like IIf([Forms]![Navigation Form]![NavigationSubform].[Form]![NavigationSubform].[Form]![4Check]=True,"4*",Null) 
    Or (COTest2.ProjectCode) Like IIf([Forms]![Navigation Form]![NavigationSubform].[Form]![NavigationSubform].[Form]![MCheck]=True,"M*",Null) 
    Or (COTest2.ProjectCode) Like IIf([Forms]![Navigation Form]![NavigationSubform].[Form]![NavigationSubform].[Form]![SCheck]=True,"s",Null) 
    Or (COTest2.ProjectCode) Like IIf([Forms]![Navigation Form]![NavigationSubform].[Form]![NavigationSubform].[Form]![QCheck]=True,"Q*",Null) 
    Or (COTest2.ProjectCode) Like IIf([Forms]![Navigation Form]![NavigationSubform].[Form]![NavigationSubform].[Form]![ECheck]=True,"E*",Null)) 
    
    AND 
    ((COTest2.FiscalYear) Between [Forms]![Navigation Form]![NavigationSubform].[Form]![NavigationSubform].[Form]![FYFrom] And [Forms]![Navigation Form]![NavigationSubform].[Form]![NavigationSubform].[Form]![FYTo]) AND ((COTest2.SumOfActualAmount)<>0) 
    AND 
    ((dbo_Project.Title)=IIf([Forms]![Navigation Form]![NavigationSubform].[Form]![NavigationSubform].[Form]![JCheck]=True,(dbo_Project.Title) Like "Job Order*",(dbo_Project.Title) Not Like "Job Order*")))
    ORDER BY COTest2.FiscalYear, COTest2.Quarter, Round([SumOfActualAmount]/[SumOfContractAmount]*100,2);
    Thanks!
    Last edited by offie; 07-12-2013 at 06:13 AM.

  2. #2
    Dal Jeanis is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Okay, it started off looking like total nonsense, but I managed to decode the first part of this:
    Code:
    ((dbo_Project.Title)=IIf(
       [Forms]![Navigation Form]![NavigationSubform].[Form]![NavigationSubform].[Form]![JCheck]=True,
       (dbo_Project.Title) Like "Job Order*",
       (dbo_Project.Title) Not Like "Job Order*")))
    Here's the Translation into English:
    Code:
    [Forms]![Navigation Form]![NavigationSubform].[Form]![NavigationSubform].[Form]![JCheck]
    
    can be coded like this
    
    [Forms]![A]![B].[Form]![C].[Form]![E]
    
    and the key becomes this
    
    ![A]    [Navigation Form]   is the name of a form (F1) in the forms collection
    ![B]    [NavigationSubForm] is the name of a control on that first form that links to a subform (F2)
    .[Form] is a property that refers to the second form (F2) that the [B] control links to   
    ![C]    [NavigationSubForm] is the name of a control on the second form that links to a subform (F3)
    .[Form] is a property that refers to the third form (F3) that the [C] control links to   
    ![E]    [JCheck] is a control on the third form (F3)
    So that's not your problem, obviously, since it worked in the prior section of your query.

    If the [JCheck] control is true, then the IIF will determine the value of this clause, and then see if that value matches (dbo_Project.Title). I can't find a reference that allows the next syntax.
    Code:
       (dbo_Project.Title) Like "Job Order*",

  3. #3
    Dal Jeanis is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    So replace that IIF with this

    Code:
    AND 
    (  (  (dbo_Project.Title) Like "Job Order*" AND 
           [Forms]![Navigation Form]![NavigationSubform].[Form]![NavigationSubform].[Form]![JCheck]=True 
       ) 
    OR 
       (   (dbo_Project.Title) NOT Like "Job Order*" AND 
           [Forms]![Navigation Form]![NavigationSubform].[Form]![NavigationSubform].[Form]![JCheck]=False 
       )
    )

  4. #4
    offie is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    176
    Thanks! It works great.

    I did this on 2 queries and for some reason their SQL are different though they look the same in design veiw, but it still works so it's all good

  5. #5
    Dal Jeanis is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Yep, you can have identical effect with different SQL, for instance

    FROM tblA, tblB WHERE tblA.KeyField = tblB.KeyField

    is equivalent to

    FROM tblA INNER JOIN tblB ON tblA.KeyField = tblB.KeyField


    Glad it all worked out.

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

Similar Threads

  1. 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
  2. Replies: 3
    Last Post: 07-10-2012, 05:23 AM
  3. Replies: 8
    Last Post: 03-07-2012, 01:18 PM
  4. Help fix SQL Statement for query
    By Budro49 in forum Queries
    Replies: 12
    Last Post: 06-21-2011, 02:26 PM
  5. Access email button messing up numbers
    By ninjafly in forum Reports
    Replies: 3
    Last Post: 08-20-2009, 04:27 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