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 always returns Null
Tim Gilbert 
    
4 years ago
Hello - I would appreciate any insight into a problem I am having with the DLookup function in VBA.

I have an small unbound form (FDatePicker) I plan to use to navigate to specific records on one of my main forms.  FDatePicker has an unbound text box formatted as short date (YYYY-MM-DD in my case).  The text box is named "DatePicker".  The form also has a button where the On Click event has the VBA I am writing.  

I am in the early stages of writing the code so I'm taking it one step at a time. Initially all I want the code to do is look up an ID number (RecordID) from a table in the database (TRecords) where the RecordDate field in the table matches the date selected by DatePicker then display the RecordID in a message box.  I have the intention to do more later but this is step one.  

This is what I wrote:
MsgBox ("RecordID = " & DLookup("[TRecords]!RecordID", "TRecords", "[TRecords]![RecordDate]=" & DatePicker))

But all I ever get back is "RecordID = ".  I never get the RecordID even though I know there would be one for the dates I use to test it.  

As one more test I wrote an extra line to tell me if the DLookup is returning a Null value:
If IsNull(DLookup("[TRecords]!RecordID", "TRecords", "[TRecords]![RecordDate]=" & DatePicker)) Then MsgBox ("It's Null")

I always get the "It's Null" statement

I have verified that the DatePicker and the RecordDate are both formatted as short date, I have also tried wrapping the DatePicker inside the CDate function just in case that DatePicker being a value from a text box had any influence - that didn't help.

What might I be missing here?  Why is what I wrote failing to return the ID intended.

Thank you
Adam Schwanz  @Reply  
           
4 years ago
MsgBox ("RecordID = " & DLookup("RecordID", "TRecords", "RecordDate=#" & DatePicker & "#"))
Tim Gilbert OP  @Reply  
    
4 years ago
Well - insert  Piccard face palm GIF here

Adam - thank you.  I can't believe I missed something so basic.  I use the # in queries but for some reason it just wasn't coming to mind last night.  Thanks again, I truly appreciate the assist - it works exactly as planned now.
Dan Jackson  @Reply  
        
4 years ago
As Requested -

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

Next Unseen

 
 
What's This?

 

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: 11/15/2026 1:25:31 AM. PLT: 1s