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 Developer Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Insert records to tables
Mario Jaile 
    
3 years ago
Have a form OrderForm that adds a new record to the table ShipAddress(relationship One) and a subform OrderDetails with a table OrderDetails(relationship Many). In the ShipAddress table there is a field with a primary key named OID, that field gets populated with a DMax("[OID]","ShipAddress")+1, through the OrderForm.(That is what my problem is)

I have a select query RenewalForm and 3 append queries ShipAddressAppendForRenewals , OrderDetailsAppendForRenewals and "ShipAddressUpdateForRenewals".

From a Command button:
DoCmd.SetWarnings False
DoCmd.OpenQuery "ShipAddressAppendForRenewals"
DoCmd.OpenQuery "OrderDetailsAppendForRenewals"
DoCmd.OpenQuery "ShipAddressUpdateForRenewals"
DoCmd.SetWarnings True

These queries add a new record for customers when the renewal date comes up. There is a unique field named LotNumber and if I restrict the queries to only one lot number it works fine. If there is more than one customer, it tries to assign the same OID to all of them with no success because of the primary key, only one customer appends and it may not be the same information required for both tables. I would like if there is more than one customer to be renew, to be able to run the queries only once and add the records of all the customers up for renewal at the same time and then print the invoices. The report name is Invoice. This is the SQL for all 3 queries:

RenewalForm SQL
SELECT ColdStorageInvoicingQuery.BilledDate, ColdStorage2323.LotNumber, ColdStorageInvoicingQuery.ShipName, ColdStorage2323.ProductDescription, ColdStorage2323.[Renewal Rate], ColdStorage2323.BoxesIn AS PalletsIn, ColdStorageInvoiceQuery2.SumOfPalletsOut, [PalletsIn]-[SumofPalletsOut] AS BillablePallets, [Renewal Rate]*[BillablePallets] AS InvAmt, ColdStorageInvoicingQuery.OID, ColdStorageInvoicingQuery.DateIn, ColdStorage2323.CID, ColdStorage2323.Fresh, ColdStorage2323.Frozen, IIf(Month([BilledDate])=2,DateAdd("d",28,[BilledDate]),DateAdd("d",31,[BilledDate])) AS [Month]
FROM (ColdStorage2323 LEFT JOIN ColdStorageInvoicingQuery ON ColdStorage2323.LotNumber = ColdStorageInvoicingQuery.ColdStorage2323.LotNumber) LEFT JOIN ColdStorageInvoiceQuery2 ON ColdStorage2323.LotNumber = ColdStorageInvoiceQuery2.LotNumber
WHERE (((ColdStorageInvoicingQuery.BilledDate)<=Date()-30) AND ((ColdStorage2323.DateClosed) Is Null))
ORDER BY ColdStorageInvoicingQuery.BilledDate, ColdStorage2323.LotNumber;

ShipAddressAppendForRenewals SQL
INSERT INTO ShipAddress ( LotNumber, Notes, ShipName, CID, EID, ShipAddress, ShipCity, ShipState, ShipPostalCode, FOrderPerson, OID, COD, Cash, Charge, Deliver, Pickup )
SELECT RenewalForm.LotNumber, RenewalForm.ProductDescription, RenewalForm.ShipName, RenewalForm.CID, [Forms]![CurrentUser]![Text4] AS Expr3, Customers.Address, Customers.City, Customers.St, Customers.PostalCode, [Forms]![CurrentUser]![Text4] AS Expr9, DMax("[OID]","ShipAddress")+1 AS Expr4, Customers.COD2, Customers.Cash2, Customers.Charge2, Customers.Deliver2, Customers.Pickup2
FROM RenewalForm INNER JOIN Customers ON RenewalForm.CID = Customers.CID;

OrderDetailsAppendForRenewals
INSERT INTO OrderDetails ( Box, WeightUnits, TWeightUnits, ExtPrice, BoxShip, QShipped, PrdtID, OID, ProductName2, Price, LotNumber )
SELECT RenewalForm.BillablePallets, RenewalForm.BillablePallets, RenewalForm.BillablePallets, RenewalForm.InvAmt, RenewalForm.BillablePallets, RenewalForm.BillablePallets, "ZzStorage01" AS Expr1, DLast("[OID]","[ShipAddress]") AS Expr2, "Renewal Storage" AS Expr3, RenewalForm.[Renewal Rate], RenewalForm.LotNumber
FROM RenewalForm;

"ShipAddressUpdateForRenewals"
UPDATE ShipAddressUpdateForRenewalsMain SET ShipAddressUpdateForRenewalsMain.ShippedDate = Date(), ShipAddressUpdateForRenewalsMain.OrderDate = Date();

Thank you for any help. If need be I am willing to pay a fee to get this to work.
Kevin Robertson  @Reply  
          
3 years ago
Screenshots of your queries? A lot easier to troubleshoot than a ton of SQL.
Mario Jaile OP  @Reply  
    
3 years ago

Mario Jaile OP  @Reply  
    
3 years ago

Mario Jaile OP  @Reply  
    
3 years ago

Mario Jaile OP  @Reply  
    
3 years ago

Mario Jaile OP  @Reply  
    
3 years ago

Mario Jaile OP  @Reply  
    
3 years ago

Mario Jaile OP  @Reply  
    
3 years ago

Mario Jaile OP  @Reply  
    
3 years ago

Mario Jaile OP  @Reply  
    
3 years ago
Please find screenshots
Kevin Yip  @Reply  
     
3 years ago
An append query adds all the records *at once*, in bulk.  That's why DMax()+1 doesn't work.  DMax() needs to look up the previous record's value in order to work.  But there is no previous record for DMax to look up if all records are added at the same time.  To use DMax+1 properly, you need to use VBA and the Recordset object to add records one at a time, via a "loop" created with Recordset.  If you are not familiar with Recordset you need to take some courses here.
Mario Jaile OP  @Reply  
    
3 years ago
Thanks for trying to help, as I stated initially for one record it works fine, I am looking help to do all the records at the same time.
Mario Jaile OP  @Reply  
    
3 years ago
I misread your comments thanks but I have no time to take courses, that it is why I am willing to pay to get this working

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developer 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: 6/16/2026 12:32:26 PM. PLT: 0s