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 Developers    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Add SubForm Data to Table
Marc Spragg 
     
4 years ago
Hi Folks, I have a Mainform with unbound controls and an add button that adds the data to the Main Table using code that seems to work great, however i also need the subform data to be added to the Table linked to the subform at the same time. Do i just need to add the subform controls into the CurrentDB Execute statement?
Thanks Marc
Marc Spragg OP  @Reply  
     
4 years ago

Adam Schwanz  @Reply  
           
4 years ago
Yea you could just add to the statement or make another one if it's a different table. Or use a recordset.
Marc Spragg OP  @Reply  
     
4 years ago
Thanks Adam, it doesn't work with both the two statements together. Either Statement works if you remove the other though, but the code for the SubF doesn't link the ID from the mainform to the detail ID
Marc Spragg OP  @Reply  
     
4 years ago

Marc Spragg OP  @Reply  
     
4 years ago

Kevin Robertson  @Reply  
          
4 years ago
If the form is unbound you will need to include all the fields in the insert statement. SAPID isn't included in the statement for your subform.
Marc Spragg OP  @Reply  
     
4 years ago
Thanks Kevin, Yeah that doesn't seem to make a difference. With both sets of code DBExecute is only working for the main form. If i take out the code for the main form the second DB Execute works but is missing the SAPID - Which i have now included in the code. I'm not sure even that the SubForm is unbound.  Record Source for the SubF is a query (not complicated). The Mainform has unbound controls but the record source is a table. The add button creates the SAPID on the click. Looking at the properties the subform is linked by SAPID / SAPID but the main form does not have a SAPID bound control if that matters.
Scott Axton  @Reply  
      
4 years ago
Marc - -
The basic problem you have here is that you are bypassing your form / subform relationship with your add button code.  The subform is not "self-aware" - it doesn't know where to get the SAPID from because you added in a record via code in the background.
I'm pretty sure you can add in the main record and the line items just fine if you do it manually - correct?

So, what needs to happen, when you execute the first INSERT you need to capture the ID that was just created by the Autonumber and then that ID needs to be passed into your second SQL INSERT for the relationship to be made.

I see that you have Developer 24.  Go watch that again to see 2 different methods for copying an order and details.  That should help you out in solving your problem.
Adam Schwanz  @Reply  
           
4 years ago
I wouldn't think that second one would work at all. Those fields are on the subform, should have to give the full name Forms!ParentFormName!SubFormName.Form!FieldName
Marc Spragg OP  @Reply  
     
4 years ago
Thanks Scott and Adam, Yeah i can add to the tables when the mainform has bound fields. I've taken a look at developer 24 but i haven't been successful with either 2 approaches. The problem is im not actually copying anything that is already committed to the table. That is what i am trying to get the form to do. What i have managed to do with the code is get an ID in both forms but strangely its creating a ID that already exists.  The subform is where you select orders details from a detail table and the mainform is the order form. Very similar to the orderform created in the lessons. What i have noticed the add button on the Sub commits the subform data right now. So i can get it to do either but not link the two together. My ultimate goal here is to have a choice on the mainform by either select a record that already exists using a combo and add the details to that ID or have it create a new ID and add the details to the new ID.
Marc Spragg OP  @Reply  
     
4 years ago

Marc Spragg OP  @Reply  
     
4 years ago

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developers.
 

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: 8/7/2026 9:14:20 PM. PLT: 1s