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 
Copy Data for Table to Form
James Hopkins 
     
2 years ago
Hey Richard and the Crew, I have created an VBA Code to Duplicate an Estimate Data from the Table to create the New Estimate into the Estimate Form. The problem I have is that the Estimate Detail Data is not transfering into the New Estimate Detail Subform. What is the best way to do this?
Alex Hedley  @Reply  
           
2 years ago
Gonna need a little bit more info here'
How are you populating the data?
Alex Hedley  @Reply  
           
2 years ago
Legacy Tip: Copy Last Record
Ludwig Willems  @Reply  
      
2 years ago
volgen :)
James Hopkins OP  @Reply  
     
2 years ago
Here's what I have:

Details    Dim db As DAO.Database
    Dim rsOriginalEstimate As DAO.Recordset
    Dim rsOriginalEstimateDetail As DAO.Recordset
    Dim rsOriginalEstimateAttachment As DAO.Recordset
    Dim rsNewEstimate As DAO.Recordset
    Dim rsNewEstimateProductDetail As DAO.Recordset
    Dim rsNewEstimateServiceDetail As DAO.Recordset
        
    ' Open the Database
    Set db = CurrentDb
    
    ' Open Recordset for the Original Estimate
    Set rsOriginalEstimate = db.OpenRecordset("SELECT * FROM EstimateT WHERE EstimateID =" & EstimateID)
    
    ' Create a New Estimate Record
    If Not rsOriginalEstimate.EOF Then
        ' Open the Estimate Form in Add Mode
        DoCmd.OpenForm "EstimateF", acNormal, , , acFormAdd, acWindowNormal

        ' Get the Estimate Recordset
        Set rsNewEstimate = Forms("EstimateF").RecordsetClone
        
        ' Copy the Estimate Record Data to the Estimate Form
        rsNewEstimate.AddNew
        rsNewEstimate!ClientID = rsOriginalEstimate!ClientID
        rsNewEstimate!PropertyID = rsOriginalEstimate!PropertyID
        rsNewEstimate!EstimateCreationDate = Now
        rsNewEstimate!EstimateName = rsOriginalEstimate!EstimateName
        rsNewEstimate!EstimateTypeID = rsOriginalEstimate!EstimateTypeID
        rsNewEstimate!EstimateStatusID = 343
      
        ' Add any Other Fields that need to be copied
        rsNewEstimate.Update
        
        ' Open Recordset for the Original Estimate Details
        Set rsOriginalEstimateDetail = db.OpenRecordset("SELECT * FROM EstimateDetailT WHERE EstimateID = " & rsOriginalEstimate!EstimateID)
        
        ' Copy each Original Estimate Product Detail to the New Estimate
        Set rsNewEstimateProductDetail = Forms("EstimateF").Controls("EstimateProductDetailF").Form.RecordsetClone
          
        ' Copy the Original Estimate Detail data to the New Estimate Product Detail Form
        rsOriginalEstimateDetail.MoveFirst
        Do Until rsOriginalEstimateDetail.EOF
            rsNewEstimateProductDetail.AddNew
            rsNewEstimateProductDetail!ProductID = rsOriginalEstimateDetail!ProductID
            rsNewEstimateProductDetail!ProductName = rsOriginalEstimateDetail!ProductName
            rsNewEstimateProductDetail!Quantity = rsOriginalEstimateDetail!Quantity
            rsNewEstimateProductDetail!UnitPrice = rsOriginalEstimateDetail!UnitPrice
            ' Copy other relevant Estimate Product Fields here
            rsNewEstimateProductDetail.Update
            rsOriginalEstimateDetail.MoveNext
        Loop
        
        ' Copy each Original Estimate Service Detail to the New Estimate
        Set rsNewEstimateServiceDetail = Forms("EstimateF").Controls("EstimateServiceDetailF").Form.RecordsetClone
        
        ' Copy the Original Estimate Detail Data to the New Estimate Product Detail Form
        rsOriginalEstimateDetail.MoveFirst
        Do Until rsOriginalEstimateDetail.EOF
            rsNewEstimateServiceDetail.AddNew
            rsNewEstimateServiceDetail!ServiceID = rsOriginalEstimateDetail!ServiceID
            rsNewEstimateServiceDetail!ServiceName = rsOriginalEstimateDetail!ServiceName
            rsNewEstimateServiceDetail!Hours = rsOriginalEstimateDetail!Hours
            rsNewEstimateServiceDetail!Rate = rsOriginalEstimateDetail!Rate
                
            ' Copy other relevant Estimate Service Fields here
            rsNewEstimateServiceDetail.Update
            rsOriginalEstimateDetail.MoveNext
        Loop

        ' Close recordsets
        rsNewEstimate.Close
        rsOriginalEstimateDetail.Close
        rsOriginalEstimateAttachment.Close
        rsNewEstimateProductDetail.Close
        rsNewEstimateServiceDetail.Close
    Else
        
        ' Code for Custom MsgBox
        MsgBox "No Estimates found.", vbInformation
    End If
    
    ' Close recordsets
    rsOriginalEstimate.Close
    
    ' Close recordsets
    Set rsOriginalEstimate = Nothing
    
    Set rsOriginalEstimateDetail = Nothing
    Set rsOriginalEstimateAttachment = Nothing
    Set rsNewEstimate = Nothing
    Set rsNewEstimateProductDetail = Nothing
    Set rsNewEstimateServiceDetail = Nothing
    Set db = Nothing

Ludwig Willems  @Reply  
      
2 years ago
James
how do you create such a detail for here?
Alex Hedley  @Reply  
           
2 years ago
Can you talk through it at a high level?
Ludwig Willems  @Reply  
      
2 years ago
Alex, I don't mean the code but the creation of the expandable detail here.
Alex Hedley  @Reply  
           
2 years ago
Sorry Ludwig I was asking James the question.

For the DETAILS thing it'll have been one of the Mods who has changed it.
James Hopkins OP  @Reply  
     
2 years ago
Sure Alex, the Estimate Form has an Estimate Product Subform and a Estimate Service Subform inside of it. I was trying to copy the Data to the Subforms, too, from the Original Estimate in the Tables.
Alex Hedley  @Reply  
           
2 years ago
I'd pretend the Form doesn't exist.

Are you just creating a copy of that? And it's related tables?

Do you need an EstimateID from EstimateT?
Using this you can get the Row(s) from both Product and Service Tables?

So you can create an INSERT Statement that will add them to your Tables. Adding the ParentID as the FK.

Then once complete just open your Form and go to the new record with the parent ID that was created.
Kevin Robertson  @Reply  
          
2 years ago
Is the data being saved to the table?
You need to Requery the Subform.
James Hopkins OP  @Reply  
     
2 years ago
Hey Guys, I check the Table for the Estimate Subform. The Data is been saved there but it is just not show on up in the Form.
Kevin Robertson  @Reply  
          
2 years ago
Did you requery the Subform?
James Hopkins OP  @Reply  
     
2 years ago
Yes, Kevin I did. It still does not show up in the Subforms. But I can Add Items to the Subforms Manual.

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/6/2026 9:53:28 AM. PLT: 0s