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 
Help with DLOOKUP in IIF
Kyle Rapp 
    
2 years ago
Hi all, I've been struggling with syntax for multiple DLOOKUPs inside of nested IIF statements. I'm wondering if anyone can help.  

Here is some background:
This is for a marina that offers various services for boats, including repairs, maintenance, winterization, etc.  I'm trying to auto assign pricing to various services, but the price of a particular service depends on the boat. (For example the type of engine, the horsepower, etc.)  I have a table called "Boats", that stores boat info and a form called "BoatsForm" for data entry, viewing and editing.  I have a table called "ServicePricing" which stores the names of services offered and the price for each service.  

The field called "service" is short text.
The field called "price" is currency.

In this example, there are 3 separate prices for engine winterization, depending on type and horsepower:
Outboard 2 Cycle with 10 HP or less
Outboard 2 cycle with 25 HP or more
Outboard 4 Cycle regardless of HP

If the enginetype is "Outboard 2 Cycle" and the HP is less than or equal to 10, I want to lookup the price for the service named "WintEngOutboardUpto10HP2Cycle"
If the enginetype is "Outboard 2 Cycle" and the HP is greater than or equal to 25, I want to lookup the price for the service named "WintEngOutboardOver25HP2Cycle"
If neither of the above are true I want to lookup the price for the service named "WintEngOutboard4Cycle"


I have an unbound text box on the BoatsForm whose control source is the following:

<CODE>=IIf("enginetype = 'Outboard 2 Cycle'" And "OuboardHP <= 10",DLookUp("Price","ServicePricing","Service = 'WintEngOutboardUpto10HP2Cycle'"),IIf("enginetype = 'Outboard 2 Cycle'" And "OuboardHP >=25",DLookUp("Price","ServicePricing","Service = 'WintEngOutboardOver25HP2Cycle'"),DLookUp("Price","ServicePricing","Service = 'WintEngOutboard4Cycle'")))</CODE>

It's not giving an error but it keeps returning the price for "WintEngOutboardUpto10HP2Cycle" no matter which values I choose for enginetype and OutboardHP on the form. (dropdowns)

Any help is appreciated.

Thanks,
Kyle
Adam Schwanz  @Reply  
           
2 years ago
Your quotations are all over, DLookup DDQ Not SQ Double Double Quotes Try these videos, see if they move you in the right direction
Sami Shamma  @Reply  
             
2 years ago
Kyle

your DLookup is only reading the first value in the table.

you need to close the Quote and re-open it again after the field. like this:

DLookUp("Price","ServicePricing","Service = '" & WintEngOutboardUpto10HP2Cycle & "'")
Kyle Rapp OP  @Reply  
    
2 years ago
Thanks Adam and Sami.  

Adam, I have watched those in the past but I need to watch them again.  I have no issue doing a Dlookup with a single criteria but with multiple criteria and nesting it all within an IIF statement I get confused.  Thanks!
Richard Rost  @Reply  
           
2 years ago
This would be MUCH easier if you used IDs instead of text fields.
Kyle Rapp OP  @Reply  
    
2 years ago
Hey guys, got it working.  Here it is:


=IIf([enginetype]="Outboard 2 Cycle" And [OutboardHP]<=25,DLookUp("Price","ServicePricing","Service = 'WintEngOutboardUpto25HP2Cycle'"),IIf([enginetype]="Outboard 2 Cycle" And [OutboardHP]>25,DLookUp("Price","ServicePricing","Service = 'WintEngOutboardOver25HP2Cycle'"),DLookUp("Price","ServicePricing","Service = 'WintEngOutboard4Cycle'")))


Thanks for the help.

Kyle
Richard Rost  @Reply  
           
2 years ago
Excellent

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: 6/22/2026 3:18:24 PM. PLT: 1s