Results 1 to 4 of 4
  1. #1
    onemred is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    2

    iff statement within a query to create a query by form

    I'm trying to create a query by form query. I would have thought the syntax within the query would have been as follows but it's not working.

    IIf([forms]![frmQBFRenewal]![Combo14]=Yes,Like "*", Is Null)




    The field that I am querying is a date field. If Combo14 is set to Yes then I don't care what dates are in the field. I want all data returned including records with no dates. If Combo14 is set to NO then I only want records that have no date entry in the field I'm querying.

  2. #2
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Just check if below gives some guidelines :

    Code:
    SELECT 
    	myTable.TheID, 
    	myTable.TheDate
    FROM 
    	myTable
    WHERE 
    	((1)=1) 
    	And 
    	(
    		(
    			IIf(Forms!frmQBFRenewal!Combo14="Yes",1=1,(myTable.TheDate) Is Null)
    		)
    	);
    Thanks

  3. #3
    onemred is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    2
    I added a calculated field "Expr2" for the sole purpose of determining if my date field is blank or has a value. I then used my new field with the IIF statement. This is how I got it to work.

    SELECT tblAccounts.ID, tblAccounts.AcctNum, tblAccounts.Company, tblAccounts.SLP, tblAccounts.[Renewal Date], tblAccounts.DateConfirmedNoRenew, IIf(IsNull([DateConfirmedNoRenew]),"blank","not blank") AS Expr2
    FROM tblAccounts
    WHERE (((IIf(IsNull([DateConfirmedNoRenew]),"blank","not blank")) Like IIf([Forms]![frmQBFRenewal]![Combo14]=Yes,"*blank","blank")))
    ORDER BY tblAccounts.[Renewal Date];

  4. #4
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Thanks for sharing the solution.

    Thanks

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

Similar Threads

  1. If statement in Query
    By Jojojo in forum Queries
    Replies: 5
    Last Post: 11-18-2011, 03:02 PM
  2. Iif Statement in query
    By evanhughes in forum Queries
    Replies: 1
    Last Post: 11-03-2011, 08:55 AM
  3. Code to create a query from a form
    By stryder09 in forum Queries
    Replies: 15
    Last Post: 10-17-2011, 01:55 PM
  4. Query (if Statement I Think?)
    By Hello World in forum Queries
    Replies: 3
    Last Post: 10-13-2011, 09:25 AM
  5. If then statement in query
    By ronnie4 in forum Queries
    Replies: 1
    Last Post: 01-20-2009, 10:49 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