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 
VBA to read data from Table
Andrew Adams 
  
2 years ago
I have a form called Detail Inspection Plan. The record source table is called Detail Inspection Plan (DIP). On the form and in the table I have the following fields, Lot Quantity, AQL, and Sample Qty. The AQL field is a combo box with the following selections: 100, .65, and 2.5. There's a table called AQLT that was created to hold the AQL Sampling Plan matrix. The table has the following fields, ID, Lot quantity Start, Lot Quantity End, AQL, and Sample Qty. The lot quantity range (Start & End) along with the applicable AQL, determins the sample qty. I want the user using the Detail Inspection form to enter in the quantity of their lot (how many pieces they have) into the Lot Quantity field and select the AQL (sample plan) they're using from the AQL combo box. In return, after they've entered in the quantity into the lot quantity field and selected their AQL; I want the Sample Qty field to automatically return a Sample Qty from the Sample Quantity field in the AQLT table. How do I achieve this using VBA in Access?  Thank you.
Andrew Adams OP  @Reply  
  
2 years ago

Richard Rost  @Reply  
          
2 years ago
This is basically a complicated DLookup statement with three criteria.

ID = Nz(DLookup("ID","AQLT","LotRangeStart<=" & LotQuantity & " AND LotRangeEnd>=" & LotQuantity & " AND AQL=" & AQL),0)

That should return the ID, or a 0 if it doesn't exist. Now just use a button or an AfterUpdate event to run that code.
Richard Rost  @Reply  
          
2 years ago
I've got a video on something similar to this coming out next week.
Andrew Adams OP  @Reply  
  
2 years ago
Awesome! Thank you very much, you're the best!
Richard Rost  @Reply  
          
2 years ago
I just posted Part 1, in fact. It's available now for members. It goes public on Monday.

DLookup Multiple Criteria
Andrew Adams OP  @Reply  
  
2 years ago
Fantastic!  Just became a Gold Member ;)  
The link says it's not available yet so I shall wait patiently... Thanks again!
Richard Rost  @Reply  
          
2 years ago
Part 2 is up now as well... if you just signed up, you may need to log off and then back on again, but you should be able to watch it right now.
Richard Rost  @Reply  
          
2 years ago
I see the gold member badge on your account here, so you should be good to go.
Andrew Adams OP  @Reply  
  
2 years ago
Thanks again sir.
Andrew Adams OP  @Reply  
  
2 years ago
Also, if you were insterested, AQL stands for Acceptable Quality Level or Limit and is a statistical method for determining if a lot of product meets the customer's requirements by using a sample qty from the lot.
Andrew Adams OP  @Reply  
  
2 years ago
Sorry... I'm just getting around to working on this. You previously stated "That should return the ID, or a 0 if it doesn't exist. Now just use a button or an AfterUpdate event to run that code."  Do I enter it directly into the Sample Qty field as an After Update event or should it be applied elsewhere?  I'm confused because there's 2 criterias (Lot Qty & AQL) that need to be entered/selected prior to the update
Sami Shamma  @Reply  
             
2 years ago
Put the code in the before update of the 'form' if your code test for correct values are entered. Put it in after update for the form if you are just doing calculations.
Andrew Adams OP  @Reply  
  
2 years ago
Hi Sami. I am doing a calculation so I will put it in an After Update event but where, as in what field, do I put it in?  The Sample Qty field or the Lot Quanityt or AQL field?  Or somewhere else?  
FYI, When I entered the code ID = Nz(DLookup("ID","AQLT","LotRangeStart<=" & LotQuantity & " AND LotRangeEnd>=" & LotQuantity & " AND AQL=" & AQL),0) in an After Update event in the Sample Qty field it doesn't return anything.  Not sure what I'm missing.
Kevin Robertson  @Reply  
          
2 years ago
Looking at your screenshot AQL is a text value (left aligned).
Was this an oversight? Should it be a Number?
If it is the correct Data Type you will need to use Double Double Quotes in your DLookup function.
Andrew Adams OP  @Reply  
  
2 years ago

Andrew Adams OP  @Reply  
  
2 years ago

Andrew Adams OP  @Reply  
  
2 years ago
Hi Kevin.  Yes, it is a text field.  I updated the code to:  
ID = Nz(DLookup("ID", "AQLT", "LotRangeStart<=" & LotQuantity & " AND LotRangeEnd>=" & LotQuantity & "" And AQL = "" & AQL), 0)
Kevin Robertson  @Reply  
          
2 years ago
Quotes are incorrect. Did you watch the video I linked to?

ID = Nz(DLookup("ID", "AQLT", "LotRangeStart<=" & LotQuantity & " AND LotRangeEnd>=" & LotQuantity & " And AQL=""" & AQL & """"), 0)

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:11:38 AM. PLT: 1s