Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Query Based on Text Box
Bryan Gravely 
    
4 years ago
I've got a form that lists movie information where the value of a true/false field is True.  At the top of this form, I have a search box where users can enter text to search the alternate tile for the movies. For most movies the alternate title is blank.  
In the query, the True/False field criteria is set to True and the alternate title criteria is set to "*" & [Forms]![F_Movie_WatchList]![MovieSearchBox] & "*".  This only returns records where the True/False is True and there actually is an alternate title.  It doesn't show all the records where the alternate title is blank.  

I've also tried the following for the alternate title criteria:
Like IIf([Forms]![F_Movie_WatchList]![MovieSearchBox] Is Null,Null,"*" & [Forms]![F_Movie_WatchList]![MovieSearchBox] & "*") => Returns blank form without a list at all.

Like IIf([Forms]![F_Movie_WatchList]![MovieSearchBox]="","","*" & [Forms]![F_Movie_WatchList]![MovieSearchBox] & "*") => Returns the form with an empty list.

IIf([Forms]![F_Movie_WatchList]![MovieSearchBox]="","",Like "*" & [Forms]![F_Movie_WatchList]![MovieSearchBox] & "*") => Returns blank form without a list at all.

One other note, it works perfectly in another form that doesn't involve the True/False field, the problems only occur when trying to combine the two.

I will post screen shots of the queries with the form results below:
Bryan Gravely OP  @Reply  
    
4 years ago

Bryan Gravely OP  @Reply  
    
4 years ago

Bryan Gravely OP  @Reply  
    
4 years ago

Bryan Gravely OP  @Reply  
    
4 years ago

Kevin Robertson  @Reply  
          
4 years ago
This should work. The "*" in the 'value if true' parameter should return all records.

Like IIf([Forms]![F_Movie_WatchList]![MovieSearchBox]="","*","*" & [Forms]![F_Movie_WatchList]![MovieSearchBox] & "*")
Juan C Rivera  @Reply  
            
4 years ago
I think that putting all this on the 1st criteria line may cause the problem just thinking if you put the alt title criteria on the line below the query will go across the down.  Just a thought.  Let us know if it works and what was the fix.
Bryan Gravely OP  @Reply  
    
4 years ago
@Kevin: I Know I tried that, but I must have had something wrong when I tried it, because it doesn't work.  But it's working now, thanks.

@Juan: I thought of this, and I actually do it that way in another form where it's the only criteria, but in this particular form, there are about 8 criteria that i'd have to duplicate if I split it onto two lines.
Kevin Yip  @Reply  
     
4 years ago
Hi Bryan, the IIf() function only works with strings and values. But in one of your expressions, you wrote:

    IIf(condition, "", Like & "*" & something & "*")

Note that there is no quotation right before "Like", so that is not a string. Normally, this returns an error; but due to some quirk, there is no error here. But IIf() still won't work, because IIf() can't handle anything other than actual values. If IIf() doesn't work, your criterion is ruined, and therefore you get no records.

In another instance, you wrote:

    Like IIf(condition, Null, "*" & something "*")

"Null" in this case is the actual value of null here. It is not something you can concatenate with "Like" to make "Like Null". The result would simply be "Like", the same way "apple" & Null equals "apple" only. So again your criterion is ruined and you get no results (and no error to tell you what was wrong).

My advice is to avoid using "Like" in this manner, because it is not really a string that you can concatenate with something else. It is an *operator*, and is treated differently by Access in the query designer. The only way to properly concatenate these things is to use VBA to construct SQL statements with string concatenation. E.g.:

    Dim s As String
    s = "SELECT MyField FROM MyTable WHERE MyField Like " & IIf(condition, "Null", SomethingElse)

Or:

    s = "SELECT MyField FROM MyTable WHERE MyField " & IIf(condition, "", "Like '*" & SomethingElse & "*'")

Note that I use quotations for "Null" and "Like" inside IIf(), because they are actual strings in this case. Everything is a string here, so they can concatenate freely with one another.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 8/8/2026 1:48:58 AM. PLT: 1s