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
Pending Approval    Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 

Anonymous 
 
Kevin Yip  @Reply  
     
4 years ago
Make sure the criterion portion of DLookup is a valid expression.  For instance, if your criterion is "[MyField]=" & Me!MyField, then if you delete the field's value on the form, the expression becomes "[MyField]=" , which is invalid and causes an error.
Daniel Schuster  @Reply  
     
4 years ago
How do I make it a valid expression? Can I create a blank option in the combo box so that instead of deleting the entry, I can have my users insert a blank entry instead?
Liam Convey  @Reply  
   
4 years ago
Try '[MyField]=' & Nz(Me!MyField,0)
Kevin Yip  @Reply  
     
4 years ago
I'm guessing your field in question is numeric, because that is what usually causes the erroneous criterion "[MyField]=" : when the numeric field becomes null.

Try this as the criterion for DLookup:

"[MyNumericField] & '' = " & Me!MyNumericField & " & ''"

Note carefully the single quotes and double quotes used above.

What this does is, it converts both sides to strings.  If the field value on the right side is a null, it is turned into a zero-length string so it can be validly compared to the string on the left side.  If the user types spaces or even gibberish text in the field (assuming you don't validate user entries), it still works.  That's because it compares string to string, and strings can be any text, unlike numerals.

If this still doesn't work for you, post your exact DLookup function.
Daniel Schuster  @Reply  
     
4 years ago
Liam, that did the trick. Thank you.

Kevin, I can't get your criterion to work. I think I'm missing where to put the closed parenthesis from the beginning of the function =DLookup(
Where do I close the parenthesis? I'm guessing that is impacting the result. I put it at the very end and it didn't work.
Also, what does Me! represent? Is that just saying you're referencing something on that form or does that need to be typed into the function?
Last point of clarity - the brackets. I know they represent the field name, but does that effect the outcomes of these functions whether I have them or not?

Thank you for the knowledge!

Kevin Yip  @Reply  
     
4 years ago
Hi Daniel, glad to see you worked it out.  Yes, you need the closing parenthesis for all functions, e.g. Dlookup(argument 1, argument 2, argument 3).  These long functions and commands are tricky, and easy to make mistakes in even for experienced users.

"Me" standards for the current form.  Writing Me!MyField makes it clear that MyField is a control on the current form.  Writing only MyField is fine too, but if you have very long code, it helps to differentiate them.  The exclamation point "!" means "is a parent of"  Newer generations of users also use period "." instead "!" to conform more to the naming conventions of the object-oriented system; e.g. Me.MyForm.

Square brackets are needed if your field names have spaces: e.g. [My field].  Yes, it is best to have field names with no spaces.  But I always use brackets in my examples to make sure they work for the user, rather than assuming the user doesn't have spaces in their field names.

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: 7/15/2026 12:54:12 PM. PLT: 1s