Results 1 to 6 of 6
  1. #1
    mike760534211 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    12

    Query IIf statement help


    I am running a query where a criteria field is populated from a form. I can get it to work correctly if i choose something in the form field but i want it to return all records if no criteria is selected. I am using the following as my IIf formula.

    Code:
    IIf(IsNull([Forms]![Custom_Reports]![txtClient])," ",Like [Forms]![Custom_Reports]![txtClient] & "*")

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Doesn't
    Code:
    Like [Forms]![Custom_Reports]![txtClient] & "*"
    work without the need for and IIF statement?
    The & "*" is usually added to handle the NULL criteria.

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    Joe's solution will work for pretty much everything except if you are entering a string and you want to find any record that contains a string.

    In that case joe's solution will find everything STARTING with the string provided if you want to show all records where the string occurs anywhere in the search field you'd need

    Code:
    like "*" & forms![custom reports]![txtclient] & "*"

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Joe's solution will work for pretty much everything except if you are entering a string and you want to find any record that contains a string.
    Not really my solution, I was just modifying the attempted solution that they posted, but that does make a good point.

  5. #5
    mike760534211 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    12
    Quote Originally Posted by rpeare View Post
    Joe's solution will work for pretty much everything except if you are entering a string and you want to find any record that contains a string.

    In that case joe's solution will find everything STARTING with the string provided if you want to show all records where the string occurs anywhere in the search field you'd need

    Code:
    like "*" & forms![custom reports]![txtclient] & "*"
    this causes an overflow if i dont put any criteria in the txt client form field. and if i do enter criteria into the txtclient field on the form i get the same error.

    Code:
    Like [Forms]![Custom_Reports]![txtClient] & "*"
    also gives overflow and crashes as well.

    Both options give the same error 2950 and the databases location is a trusted location.

  6. #6
    GAtkins is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    11
    Like "*" & [Forms]![CorpBondSearch]![SecName] & "*"

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

Similar Threads

  1. How to use iif statement in a query
    By mdnikki in forum Queries
    Replies: 5
    Last Post: 06-13-2013, 07:31 AM
  2. 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
  3. Replies: 3
    Last Post: 07-10-2012, 05:23 AM
  4. query iif statement help
    By swat in forum Queries
    Replies: 4
    Last Post: 09-30-2011, 11:48 AM
  5. Query/IiF statement
    By peacepower in forum Queries
    Replies: 1
    Last Post: 08-23-2011, 04:05 PM

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