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 Developer Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Triple DLoopkup function
Klaas van Eijkern 
     
3 years ago
Hello,

Can someone help me with the DLookup function below.
I have two Tables, named: PrijslijstenOpdrachtgeverT and Bedrijven.
The Form "Bedrijfsgegevens" based on the Table "Bedrijven" includes the Fields of FormaatContainer1 and NaamOpdrachtgever.
I want to look up the PrijsPerReiniging based the Table PrijslijstenOpdrachtgeverT with:

Private Sub PrijsPerReiniging_AfterUpdate()
   PrijsPerReiniging = DLookup("PrijsPerReiniging", "PrijslijstenOpdrachtgeverT", "FormaatContainer1=" & DLookup("FormaatContainer1", "Bedrijven", "Bedrijf='" & Bedrijf & "'" AND "NaamOpdrachtgever=" & DLookup("NaamOpdrachtgever", "Bedrijven", "Bedrijf='" & Bedrijf & "'", 0)))
End Sub


However, I do not get a value in the Field PrijsPerReiniging.
I've watched Richard's videos and I still can't figure it out.

Who can help me.

Thanks, Klaas
Alex Hedley  @Reply  
           
3 years ago
If you split the DLOOKUPs into single calls and print them do they have a value?
Klaas van Eijkern OP  @Reply  
     
3 years ago
Hey Alex,
I've tried that, but no value at all.
Kevin Yip  @Reply  
     
3 years ago
Change this portion:

    DLookup("NaamOpdrachtgever", "Bedrijven", "Bedrijf='" & Bedrijf & "'", 0)

to this:

    DLookup("NaamOpdrachtgever", "Bedrijven", "Bedrijf='" & Bedrijf & "'")

Just a slight syntax error.
Klaas van Eijkern OP  @Reply  
     
3 years ago
Hey Kevin,
I've made the change, but still no value in that field.
What else could it be?
Alex Hedley  @Reply  
           
3 years ago
If you hardcode the DLOOKUP with a value you know exists does it return anything?
Alex Hedley  @Reply  
           
3 years ago
Is Bedrijf a string?
Klaas van Eijkern OP  @Reply  
     
3 years ago
In the Table "Bedrijven" I can hardcode the Field with the value ' 23,50. That works if I open the Form "Bedrijfsgegevens".
"Bedrijf" is a Short Text Field, the name of a company, within the Table Bedrijven. It's not a string.
Alex Hedley  @Reply  
           
3 years ago
If you add a button to the form and MsgBox Bedrijf what do you get?

Short Text = String
The reason I asked was people wrap Numbers in quotes which a usual error.
Klaas van Eijkern OP  @Reply  
     
3 years ago
Added the Button. It gives me the Name of the Company. Which is good.
Kevin Yip  @Reply  
     
3 years ago
Hi Klaas, I spot another error.  This portion:

   DLookup("FormaatContainer1", "Bedrijven", "Bedrijf='" & Bedrijf & "'" AND "NaamOpdrachtgever=" ... ...

should be:

   DLookup("FormaatContainer1", "Bedrijven", "Bedrijf='" & Bedrijf & "' AND NaamOpdrachtgever="

The keyword "AND" should be inside the string, not outside.
Klaas van Eijkern OP  @Reply  
     
3 years ago
Sorry Kevin, if I change it to Bedrijf & "' AND NaamOpdrachtgever="..... the "' returns automatically back to "'".
Kevin Yip  @Reply  
     
3 years ago
Make sure there is no line break within "' AND NaamOpdrachtgever=".  If you accidentally hit Enter after "', Access will auto-correct it to "'".  But "AND" has to be inside that string, that is for certain.  

You may consider rewriting the code in smaller pieces, both to improve readability and help you troubleshoot:

Private Sub PrijsPerReiniging_AfterUpdate()
   Dim c1 As Variant, c2 As Variant
   c1 = DLookup("NaamOpdrachtgever", "Bedrijven", "Bedrijf='" & Bedrijf & "'")
   MsgBox "c1 = " & c1
   c2 = DLookup("FormaatContainer1", "Bedrijven", "Bedrijf='" & Bedrijf & "' AND NaamOpdrachtgever=" & c1)
   MsgBox "c2 = " & c2
   PrijsPerReiniging = DLookup("PrijsPerReiniging", "PrijslijstenOpdrachtgeverT", "FormaatContainer1=" & c2)
End Sub

The above MsgBox statements help you check if the expected values are returned.
Klaas van Eijkern OP  @Reply  
     
3 years ago
Hey Kevin, I still had an issue with the last DLookup.
I fixed it with:
PrijsPerReiniging = DLookup("PrijsPerReiniging", "BedrijfPrijsContainerQ", "Bedrijven.FormaatContainer1= forms!bedrijfsgegevens!formaatcontainer1 and NaamOpdrachtgever= forms!bedrijfsgegevens!NaamOpdrachtgever")

Thank you very much for helping me.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developer 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/2/2026 7:10:29 AM. PLT: 2s