Results 1 to 2 of 2
  1. #1
    LonghronJ is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    150

    Query based on text box from a form


    I have a form that has a text box which a user can fill to filter the form. If the text box is left empty, I would like to show all the records. If the text box is filled with a word/phrase, I'd like the result to show records containing the word or phrase in the text box. My criteria in the query is
    Code:
    Like "*" & [forms]![myForm]![myTextbox] & "*"
    I have used this expression in many queries and it seems to work. However, this particular query is not returning any records that have empty/null when the user does not fill in a value in the text box. Any ideas?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    But you don't want the Null records if parameter is input?

    Need to handle the Null. Construct a field in query with expression:

    Nz([fieldname], "None")

    or

    IIf([fieldname] Is Null, "None", [fieldname])

    Review http://allenbrowne.com/QueryPerfIssue.html

    Apply your criteria to that field.

    Or don't use dynamic parameterized query (I NEVER have). Use VBA code to dynamically construct filter string. Review http://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: 3
    Last Post: 07-12-2017, 12:03 PM
  2. Replies: 5
    Last Post: 08-30-2016, 12:55 PM
  3. Replies: 1
    Last Post: 08-04-2014, 07:37 AM
  4. Replies: 1
    Last Post: 03-27-2014, 06:42 AM
  5. Replies: 1
    Last Post: 08-04-2011, 04:17 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