Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
IIF statement return
Tom Henrikson 
       
3 years ago
I have 2 numeric fields on a form.  I need an IIF statement to search using those values, which may or may not be populated.  My logic is
IIF(InvoiceNumberHigh = "" or is null, iif(InvoiceNumberLow = "" or is null,SearchField = ???,SearchField >=
InvoiceNumberLow),iif(InvoiceNumberLow = "" or is null,SearchField <= InvoiceNumberHigh, SearchField between InvoiceNumberLow and InvoiceNumberHigh))

I am struggling with the syntax of ???, or what to return if both InvoiceNumberLow and InvoiceNumberHigh are "" or null.  I've tried "*", """"Like "*""" and most permutations of it.

Help me Obi Wan Kenobi.  You're my only hope.
Kevin Robertson  @Reply  
          
3 years ago
The syntax of your IIF function is wrong.
IIF Function

Also watch: Null

IIF(FieldName = "" or IsNull(FieldName), Value If True, Value If False)
Tom Henrikson OP  @Reply  
       
3 years ago
Thanks, Kevin.  My bigger question is what goes in the ??? place?  If InvoiceNumberHigh is blank, and InvoiceNumberLow is blank, what is the syntax to make the return the equivalent of "*" ?
Scott Axton  @Reply  
        
3 years ago
Check out the Combining Names video.  You are going to need a nested IIF() statement.

IIF(FieldName1 = "" or IsNull(FieldName1), Value If True, IIF(FieldName2 = "" or IsNull(FieldName2),Value If True,Value if Neither are True)

Kevin Yip  @Reply  
     
3 years ago
Hi Tom, you need both a lower limit and upper limit to filter anything.  If either is blank, nothing should be or could be done.  To answer your question, there is no "*" option in that situation.  So if the user doesn't provide both lower and upper limits, you need to have the user do so before the IIf() function is run.  In my old job, when the user typed in either a lower or upper limit, the other limit would be automatically filled in as the same value (see picture below), so both fields would not be blank, and would guarantee to return at least one record, if it existed.  And the user could enter a different upper or lower limit if he wanted to.  If the user didn't enter anything, nothing would be done.  This is really about user interface design, and you can do it differently if you want.  This is not something a single IIf() function can do, so you may need VBA.
Kevin Yip  @Reply  
     
3 years ago

Tom Henrikson OP  @Reply  
       
3 years ago
Thank you, Kevin.  That's not the answer I wanted, but you did answer my question.  I'll add default values to my form until I get the opportunity to research a VBA solution.
Scott Axton  @Reply  
        
3 years ago
Tom if you take a look at the Search Form 2.0 video, Richard shows this with dates and credit limit.  It is a little more involved writing the SQL but by having the MinSearch and MaxSearch I think that will help you achieve what you are trying to do.
As Kevin indicated it isn't really possible in a regular query.

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: 5/7/2026 12:56:39 PM. PLT: 1s