Results 1 to 4 of 4
  1. #1
    ksamaniego is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    4

    Complex IIF Statement

    Hello Everyone,



    I have a query that based upon Teacher Reg will pull up if they opted for a district, they have checked to teach in a particular area, and if they are certified in a specified area.

    I have all that working. From here, I want to see if they have other certifications along with the one they opted for. So, I have a nested select statement in an OR clause to pull up the information in an IIF statement based on if the checkbox I made is checked or not checked.

    I have this statement for my IIF Statement:
    Code:
    (
    
    	IIf(
    		[Forms]![Find Sub]![AllCert].[Value]=-1,
    		
    		IN (SELECT [PersonID] FROM [PersonCert] 
    		WHERE [PersonCert].[Name] 
    		LIKE [Forms]![Find Sub]![Cert].[Value] & "*")
    
    		, " "
    	)
    )
    Keeps returning when I run the query that it's too complex.

    I'm pretty new to Access and would appreciate some help :-)

    Thanks in advance!

    -Kyle S.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,742
    Please show us all the code.

    What exactly are you trying to do?

  3. #3
    ksamaniego is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    4
    You should read the post first time


    Here's the Code:

    Code:
    SELECT DISTINCTROW [Person Table].[FirstName] & " " & [Person Table].[LastName] AS FullName, [Site Table].name, PersonCert.Name, SubPosition.SkillLevel, Positions.Name, PersonCert.ExpirationDate, [Person Table].Phone, [Site Table].Phone, [Person Table].Person_ID
    FROM [Site Table] INNER JOIN (Positions INNER JOIN (((PersonCert INNER JOIN [Person Table] ON PersonCert.PersonID = [Person Table].Person_ID) INNER JOIN SubPosition ON [Person Table].Person_ID = SubPosition.SubstituteID) INNER JOIN SubSite ON [Person Table].Person_ID = SubSite.SubstituteID) ON Positions.Position_ID = SubPosition.Position_ID) ON [Site Table].Site_ID = SubSite.SiteID
    WHERE ((([Site Table].name) Like [Forms]![Find Sub]![SiteName].[Value] & "*") AND ((PersonCert.Name) Like [Forms]![Find Sub]![Cert].[Value] & "*") AND ((Positions.Name) Like [Forms]![Find Sub]![JobTitle].[Value] & "*") AND ((Positions.Inactive)=False)) OR ((([Site Table].name) Like [Forms]![Find Sub]![SiteName].[Value] & "*") AND ((Positions.Name) Like [Forms]![Find Sub]![JobTitle].[Value] & "*") AND (([Person Table].Person_ID)=(IIf([Forms]![Find Sub]![AllCert].[Value]=-1,([Person Table].[Person_ID]) In (SELECT [PersonID] FROM [PersonCert] 
    		WHERE [PersonCert].[Name] 
    		LIKE [Forms]![Find Sub]![Cert].[Value] & "*"),' '))) AND ((Positions.Inactive)=False));
    Last edited by ksamaniego; 08-08-2011 at 09:43 AM. Reason: Left out response

  4. #4
    ksamaniego is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    4

    asdf

    Okay, response time since it didn't show up. Double posting... I have a forum with four fields, three text areas, and a check box.

    Say if I wanted to find a person from school "X", with Certification "Y", and teaching area "Z". That query would return results for printing.

    From here, I want to not only display the previous selected people, I want to see if there have other certifications along side the previously selected area.

    To do so, I created a sub query:
    Code:
    (SELECT [PersonID] FROM [PersonCert] 
    		WHERE [PersonCert].[Name] 
    		LIKE [Forms]![Find Sub]![Cert].[Value] & "*")
    Which works. But, what I really want it to do is only display those results based on if that check box is true.

    So, I put the statement in a IIF statement and then placed it in the field and ran the test to see if it worked:
    Code:
    (IIf([Forms]![Find Sub]![AllCert].[Value]=-1,([Person Table].[Person_ID]) In (SELECT [PersonID] FROM [PersonCert] 
    		WHERE [PersonCert].[Name] 
    		LIKE [Forms]![Find Sub]![Cert].[Value] & "*"),' '))
    Returns that it's too complicated.

    Here's the overall query:
    Code:
    SELECT DISTINCTROW [Person Table].[FirstName] & " " & [Person Table].[LastName] AS FullName, [Site Table].Name, PersonCert.Name, SubPosition.SkillLevel, Positions.Name, PersonCert.ExpirationDate, [Person Table].Phone, [Site Table].Phone, [Person Table].Person_ID
    FROM [Site Table] INNER JOIN (Positions INNER JOIN (((PersonCert INNER JOIN [Person Table] ON PersonCert.PersonID = [Person Table].[Person_ID]) INNER JOIN SubPosition ON [Person Table].Person_ID = SubPosition.[SubstituteID]) INNER JOIN SubSite ON [Person Table].[Person_ID] = SubSite.[SubstituteID]) ON Positions.[Position_ID] = SubPosition.[Position_ID]) ON [Site Table].[Site_ID] = SubSite.[SiteID]
    WHERE ((([Site Table].Name) Like [Forms]![Find Sub]![SiteName].[Value] & "*") AND ((PersonCert.Name) Like [Forms]![Find Sub]![Cert].[Value] & "*") AND ((Positions.Name) Like [Forms]![Find Sub]![JobTitle].[Value] & "*") AND ((Positions.Inactive)=False)) OR ((([Site Table].Name) Like [Forms]![Find Sub]![SiteName].[Value] & "*") AND ((Positions.Name) Like [Forms]![Find Sub]![JobTitle].[Value] & "*") AND (([Person Table].Person_ID)=(IIf([Forms]![Find Sub]![AllCert].[Value]=-1,([Person Table].[Person_ID]) In (SELECT [PersonID] FROM [PersonCert] 
    		WHERE [PersonCert].[Name] 
    		LIKE [Forms]![Find Sub]![Cert].[Value] & "*"),' '))) AND ((Positions.Inactive)=False));

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

Similar Threads

  1. SQL For Complex Inner Join
    By compooper in forum Queries
    Replies: 1
    Last Post: 07-26-2011, 08:18 AM
  2. Complex query to me anyway
    By AndycompanyZ in forum Queries
    Replies: 3
    Last Post: 06-28-2011, 03:08 PM
  3. Too Complex to be evaluated - HELP!
    By awmmoore in forum Queries
    Replies: 2
    Last Post: 06-06-2011, 10:23 AM
  4. Complex Joins??
    By objNoob in forum Queries
    Replies: 0
    Last Post: 03-16-2010, 02:42 PM
  5. Replies: 2
    Last Post: 08-26-2009, 10:43 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