Results 1 to 4 of 4
  1. #1
    r32chaos is offline Novice
    Windows 8 Access 2013
    Join Date
    Aug 2014
    Posts
    2

    Filter Query Criteria via Textbox in a form


    I am displaying a list box in a form (Requests), this list box contains all records. I have a combobox which contains 3 choices; All, Open, Completed. After a selection in the combobox, a textbox (statusFilterA) is populated as follows: All = "*", Open = <> "Completed", Completed = "Completed".

    StatusFilterA unbound textbox contains: =IIf([statusfilter]="All","*",IIf([statusfilter]="Open","<>""Completed""",IIf([statusfilter]="Completed","Completed")))

    A query field contains the following criteria: Like "*" & [Forms]![Requests]![StatusFilterA] & "*"

    Problem is, "All" and "Completed" works fine but the "Open" choice does not work.

    For the time being, I made a 2nd Listbox which is made visible whenever "Open" is selected and this Listbox runs off of a new Query which contains the criteria Not Like "Completed". Of course the other Listbox, which can display "*" and "Completed" is made invisible.

    So, every time a choice is made in the combobox, it either hides the first listbox and displays the 2nd, or visa versa.

    I wish there was a way to accomplish the exclusion of "Completed" records when "Open" is selected. I tried many different methods and nothing worked.

    Any help will be very much appreciated.

    Regards

  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
    It doesn't work because <> operator results in bad syntax. The query ends up with two operators (LIKE, <>).

    Try:
    =IIf([statusfilter]="Open", "[!C]", IIf([statusfilter]="Completed", "Completed", ""))

    Don't use the first wildcard.

    LIKE [Forms]![Requests]![StatusFilterA] & "*"


    I never use dynamic parameterized query. I use VBA to construct filter criteria and set form Filter and FilterOn properties or pass criteria to form or report when opening.
    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.

  3. #3
    r32chaos is offline Novice
    Windows 8 Access 2013
    Join Date
    Aug 2014
    Posts
    2
    Quote Originally Posted by June7 View Post
    It doesn't work because <> operator results in bad syntax. The query ends up with two operators (LIKE, <>).

    Try:
    =IIf([statusfilter]="Open", "[!C]", IIf([statusfilter]="Completed", "Completed", ""))

    Don't use the first wildcard.

    LIKE [Forms]![Requests]![StatusFilterA] & "*"


    I never use dynamic parameterized query. I use VBA to construct filter criteria and set form Filter and FilterOn properties or pass criteria to form or report when opening.
    Thank you!! This worked perfectly!
    And you are right; I need to be using VBA to construct filter criteria etc. Is there any particular VBA book you would recommend? I really need to get a grasp on it.

    Again, thank you!!

    Kind Regards

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I don't have any books dedicated to programming in Access. This one sounds interesting: Access™ 2007 Programming by Example with VBA, XML, and ASP by Julitta Korol, Wordware Publishing, Inc. I expect there is a later edition.
    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. Form Textbox based on a Query Criteria
    By Peace in forum Queries
    Replies: 4
    Last Post: 05-07-2014, 01:05 PM
  2. Query criteria based on Form TextBox value
    By stildawn in forum Queries
    Replies: 8
    Last Post: 11-10-2013, 04:53 PM
  3. Replies: 6
    Last Post: 09-23-2013, 03:17 PM
  4. Replies: 1
    Last Post: 12-04-2011, 06:33 PM
  5. Replies: 1
    Last Post: 10-28-2011, 02:46 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