Results 1 to 2 of 2
  1. #1
    HelpDesk is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jun 2015
    Posts
    42

    Question Using Option Box to Select Criteria

    I am trying to use option boxes on a search form to select how the user will search. There are 3 option boxes and depending on which one the user selects I want it to run a certain criteria. I would like to do it in one query instead of using multiple queries. I am using IFF statements in the criteria field. Here is my SQL code:



    Code:
    SELECT Devices.[Device ID], Devices.Description, Devices.Location, Devices.Upstream
    FROM Devices
    WHERE (((Devices.[Device ID])=IIf([Forms]![SearchForm]![OptionFMB]=True,([Devices].[Device ID]) Like [Forms]![SearchForm]![SearchBox] & "*",Null))) OR
    (((Devices.Description)=IIf([Forms]![SearchForm]![OptionDescription]=True,([Devices].[Description]) Like [Forms]![SearchForm]![SearchBox] & "*",Null))) OR
    (((Devices.Location)=IIf([Forms]![SearchForm]![OptionLocation]=True,([Devices].[Location]) Like [Forms]![SearchForm]![SearchBox] & "*",Null)))
    ORDER BY Devices.[Device ID];
    I try to run the search and it is just pulling up Null. Any ideas where I am going wrong?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Recommend not trying to construct filter criteria within query (I NEVER use dynamic parameterized queries). Build filter string with VBA and pass it to form or report with OpenForm or OpenReport methods or set form Filter property. Review http://www.allenbrowne.com/ser-62.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 4
    Last Post: 07-18-2014, 10:51 AM
  2. Replies: 5
    Last Post: 08-02-2012, 09:44 AM
  3. Replies: 11
    Last Post: 01-25-2012, 09:46 AM
  4. Replies: 6
    Last Post: 12-30-2011, 08:09 PM
  5. Replies: 1
    Last Post: 05-05-2011, 09:21 AM

Tags for this Thread

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