Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228

    using the IIF statement in query criteria.

    This is all relative to one form "search_timesheets" and one table "Timesheets".



    I am trying to have a form with a list of combo boxes that will each list data from one of the fields in the table Timesheets. The user will use these combo boxes to filter data on a query that will then bring up a form with the results.

    Below is my attempt:


    Code:
    IIf([Forms]![search_timesheets]![staff_name_combo] Is Null,([Timesheets].[Name_Updated])="*" Or Is Null,([Timesheets].[Name_Updated])=[Forms]![search_timesheets]![staff_name_combo])
    This isn't working. To explain what I want this to do:

    If nothing is in a combo box then the query doesnt need to use that combo box as a filter. I want it to ignore it. So what I've attempted Is for it to do a 'wildcard' search (I believe thats what its called). But, If something is selected (not null) then I want that value to be used.

    Im not having much luck at the moment and im hoping someone can point me in the right direction. Thanks!

    If the combo box is null

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    1. the test for null is: iif( ISNULL(forms!xxx!timesheet), ..

    2. the 2nd part of IIF , ,([Timesheets].[Name_Updated])="*" Or Is Null,,
    , must be a value, not a decision

  3. #3
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Code:
    Like "*" & [Forms]![search timesheets]![project_name_combo] & "*" Or Is Null
    seems to do the job.

  4. #4
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    I wanted the second part to also contain null values. But I see what you mean. I have actually done this before I was just trying to make it more complex than it needed to be. Thanks for the reply.

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

Similar Threads

  1. Setting Query Criteria using Iif Statement
    By thexxvi in forum Access
    Replies: 7
    Last Post: 12-14-2015, 01:27 PM
  2. Replies: 2
    Last Post: 10-20-2015, 02:01 PM
  3. If statement in query - criteria help!
    By fluffyvampirekitten in forum Queries
    Replies: 2
    Last Post: 10-14-2015, 04:09 AM
  4. Replies: 5
    Last Post: 07-02-2014, 07:13 AM
  5. IIf Statement in Query Criteria
    By kyle87 in forum Queries
    Replies: 8
    Last Post: 07-29-2013, 12:31 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