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 
DLookup Being Evil
Bill Carver 

2 years ago
I'm trying to use dlookup in this way.

Private Sub newbtn_Click()
Dim winuser As String
Dim supervisorname As String
winuser = GetUserName()
supervisorname = DLookup("SupervisorName", "Supervisors", "windowsuser=" & winuser)
MsgBox (supervisorname)

the msgbox is simply a way to verifiy things are working.  It never executes far enough for that msgbox to come up.  

WHat I get instead is

run-time error '2471'
The expression you entered as a query paramenter produced this error 'carver'

Carver being the username returnd from windows on this one.

It is querying a field called SupervsorName in a table called supervisor and filtering by the field windowsuser"

All field names and table names I've made sure that I'm even using the same case.  

BTW SupervisorName is a calculated field in a table that is linked.  I've also tried this with a query (my original choice to concatenate the first and last name) and received the same error.
Kevin Robertson  @Reply  
          
2 years ago
You need to use Double Double Quotes
Also, use the NZ Function in case a Null is returned.

supervisorname = Nz(DLookup("SupervisorName", "Supervisors", "windowsuser=""" & winuser & """"),"")
Sami Shamma  @Reply  
             
2 years ago
See, DLookup is not evil after all. lol
Bill Carver OP  @Reply  

2 years ago
Well maybe not entirely evil but I guess more like "Monty Burns" evil.  Thanks.  It worked.
Jeffrey Kraft  @Reply  
      
2 years ago
DLookup isn't evil... Double Double quotes on the other hand.
Kevin Yip  @Reply  
     
2 years ago
Richard's guide to Evil Access Stuff
Sami Shamma  @Reply  
             
2 years ago
I remember Richard saying that you will get used to Double Double quotes, and I thought to myself that will never happen to me. Fast forward, I find myself writing code with tons of "" and sometimes they work first time.

Lesson learned, never doubt our Guro lord
Jeffrey Kraft  @Reply  
      
2 years ago
I try not to.  i try at least once on my own. If I succeed it's a time to celebrate. If I screw up, I either try again, or head off to Chat Gpt.  And then I get scolded :D

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/24/2026 9:27:10 AM. PLT: 0s