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 
DLookup
Robert Sena 
    
4 years ago
The following is what I wrote for my form text box

=DLookUp("ProjectUnitNoID","ProjectMaterialsT","ProjectItemID=" & [ProjectMaterialID])

Works great but I want it to display the information designated by the ProjectItemID which is in a different table. I don't want the ProjectItemID (Number) displayed but the related field instead.

Can it be done?
Adam Schwanz  @Reply  
           
4 years ago
Sure
Dim X, Y
X =DLookUp("ProjectUnitNoID","ProjectMaterialsT","ProjectItemID=" & [ProjectMaterialID])
Y =DLookUp("TextField","OtherTable","ProjectUnitNoID=" & X)
Robert Sena OP  @Reply  
    
4 years ago
I can only do it with code?  Would it placed in "After Update"?
Adam Schwanz  @Reply  
           
4 years ago
Put it in any relevant event, if you need the value after you enter a value somewhere else then afterupdate is fine. The on current event of the form is probably good too.

Or you could put it in a query, base the form on it.
Make an expression
ProjUnit: DLookUp("ProjectUnitNoID","ProjectMaterialsT","ProjectItemID=" & [ProjectMaterialID])

Then make second expression
TextField: DLookUp("TextField","OtherTable","ProjectUnitNoID=" & ProjUnit)
Robert Sena OP  @Reply  
    
4 years ago
Adam

One more question

Dim X, Y (As what?) Integer?
X =DLookUp("ProjectUnitNoID","ProjectMaterialsT","ProjectItemID=" & [ProjectMaterialID])
Y =DLookUp("TextField","OtherTable","ProjectUnitNoID=" & X)

Adam Schwanz  @Reply  
           
4 years ago
In this case you dont have to declare it, them being type variant is fine with no as choice. But you could do integer
Kevin Yip  @Reply  
     
4 years ago
X and Y can't be integer (or string) because that would cause a run-time error if DLookup returned Null.  X and Y must be variant to avoid that.  Dim X is the same as Dim X As Variant.  If you must declare them with a type, use the Nz() function to handle possible Null value.

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/2/2026 7:09:20 AM. PLT: 1s