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 
Sending VALUES to functions
Richard 

15 years ago
At least once a week I get an email from someone with the following problem (or some variation of it), so I wanted to post it here so you all can benefit. The student is trying to use a DLOOKUP function or build an SQL statement that is reading a form field like this:

Answer = DLOOKUP("FirstName","CustomerT","CustomerID=Forms!CustomerF!CustomerID")

SOMETIMES this will work. MUCH of the time, however, it will NOT. This is because you're sending a reference to that form field to the DLOOKUP function. It's better to send the VALUE itself, like this:

Answer = DLOOKUP("FirstName","CustomerT","CustomerID=" & Forms!CustomerF!CustomerID)

See the difference? It's subtle. Notice the quotes. What happens is that Access will determine the value of the CustomerID FIRST and then your function becomes:

Answer = DLOOKUP("FirstName","CustomerT","CustomerID=1001")

Whatever that value happens to be gets placed in there first and then the DLOOKUP is performed. The same thing happens with SQL statements...

MySQL = "SELECT * FROM CustomerT WHERE State=Forms!MyForm!State"

Should instead be:

MySQL = "SELECT * FROM CustomerT WHERE State='" & Forms!MyForm!State & "'"

NUMERIC values don't require quotes. TEXT STRINGS require quotes (use either single ' quotes or double "" double quotes). DATE values require pound # signs, like:

MySQL = "SELECT * FROM CustomerT WHERE CustomerSince>#" & Forms!MyForm!BeginDate & "#"

Remember this. Now go forth, build databases, and make me proud.

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: 5/18/2026 2:38:59 AM. PLT: 1s