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 
UpDate SQL
Maarten Brusselers 
   
3 years ago
Yesterday you guys helped me with getting my seeds balance into the table with the my seeds used form.  I am now trying to update the same balance with my seeds bought.  When I the same method I get two entries in the SeedStockT Table, one from the form and one from the SQL.  I first tried to get around this by making my form unbound and only use the SQL but that didn't work. Next I tried to use SQL update but can't get that to work either. By refreshing the form before the update I tried to book the form data first and then run the SQL to get the balance in the table.

Here is the SQL:
Me.Refresh

Dim B
Dim NB
Dim LastD
        LastD = DMax("SeedDate", "SeedStockT", "ProductID=" & SaladTypeCombo.Column(0))
        B = DLookup("Balance", "SeedStockT", "ProductID=" & SaladTypeCombo.Column(0) & " And SeedDate=#" & LastD & "#")
        NB = B + SeedsBought
        
        
        DoCmd.RunSQL "UPDATE SeedStockT SET SeedStckT.Balance = " & VAL(NB) & " WHERE SeedStockT.ProductID= & SaladTypeCombo.Column(0) & " And SeedDate=#" & LastD & "#";

Any help again much appreciated.
Maarten Brusselers OP  @Reply  
   
3 years ago

Maarten Brusselers OP  @Reply  
   
3 years ago
The SQL runs in the Supplier textbox after update
Maarten Brusselers OP  @Reply  
   
3 years ago
There was a typo in SeedStockT but it still doesn't work

Private Sub Supplier_AfterUpdate()

Me.Refresh

Dim B
Dim NB
Dim LastD
        LastD = DMax("SeedDate", "SeedStockT", "ProductID=" & SaladTypeCombo.Column(0))
        B = DLookup("Balance", "SeedStockT", "ProductID=" & SaladTypeCombo.Column(0) & " And SeedDate=#" & LastD & "#")
        NB = B + SeedsBought
        
        
        DoCmd.RunSQL "UPDATE SeedStockT SET SeedStockT.Balance = " & VAL(NB) & " WHERE SeedStockT.ProductID= & SaladTypeCombo.Column(0) & " And SeedDate=#" & LastD & "#";
Maarten Brusselers OP  @Reply  
   
3 years ago
The form posts the fields but the SQL does not update the balance
Kevin Robertson  @Reply  
          
3 years ago
You are missing a Double Quote after SeedStockT.ProductID=

DoCmd.RunSQL "UPDATE SeedStockT SET SeedStockT.Balance = " & VAL(NB) & " WHERE SeedStockT.ProductID=" & SaladTypeCombo.Column(0) & " And SeedDate=#" & LastD & "#";
Maarten Brusselers OP  @Reply  
   
3 years ago
Thanks Kevin, you were right, the double quote was missing. However, it still does not post the balance, only the form fields.
Kevin Robertson  @Reply  
          
3 years ago
The image of your form posted above doesn't seem to have a balance field. How are you displaying the balance?
Maarten Brusselers OP  @Reply  
   
3 years ago
It doesn't.  I only have the balance field in the SeedStockT table.  I thought that I could do the entire SQL balance update sequence by putting the code in the supplier_AfterUpdate Sub.  Is that not correct?  In my SeedsUsed yesterday I did not have the balance in the form either and that worked.
Maarten Brusselers OP  @Reply  
   
3 years ago

Maarten Brusselers OP  @Reply  
   
3 years ago
This is the form that I worked on yesterday.  The form source is my PlantingT but I used the SQL in the textbox Quantity to post the balance in SeedStockT

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/26/2026 3:25:47 PM. PLT: 1s