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 
Record Set to duplicate
Mark Pierce 
     
3 years ago
I have created a record set to duplicate the record on a form and the records on a continues subforum. However I keep getting some errors that I can't get past.

The first:
"The changes you requested to the table were not successful because they would create duplicate values in the index, primary key or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries"

I am guessing this is in relation to the Parent ID and the subform linked ID.

here is the code:

DetailsPrivate Sub CreateRedress2_Click()


    ' Declare variables for form and subform recordsets
    Dim rsForm As DAO.Recordset
    Dim rsSubform As DAO.Recordset
    
    ' Set form recordset to all records
    Set rsForm = Me.RecordsetClone
    rsForm.MoveFirst
    
    ' Loop through all records on form
    Do Until rsForm.EOF
    
        ' Set subform recordset to all records for current form record
        Set rsSubform = Me.TLLinerHanger4inchSubF_F2200170.Form.RecordsetClone
        rsSubform.FindFirst "TraceListEquipID = " & rsForm("ID").Value
        
        ' Loop through all records on subform
        Do Until rsSubform.EOF
        
            ' Add new record to form recordset
            rsForm.AddNew
            
            ' Copy values from current record to new record
            rsForm.Fields("PN").Value = rsForm.Fields("PN").Value
            rsForm.Fields("Revision number").Value = rsForm.Fields("Revision number").Value
            
            ' Add new record to subform recordset
            rsSubform.AddNew
            
            ' Copy values from current record to new record
            rsSubform.Fields("PartNum").Value = rsSubform.Fields("PartNum").Value
            rsSubform.Fields("Rev").Value = rsSubform.Fields("Rev").Value
            
            ' Update form and subform recordsets
             rsForm.Update
             rsSubform.Update
            
            ' Move to next subform record
            rsSubform.MoveNext
            
        Loop
        
        ' Move to next form record
        rsForm.MoveNext
    
    Loop
    
    ' Refresh form and subform
    Me.Requery
    Me.TLLinerHanger4inchSubF_F2200170.Requery
    
End Sub
Mark Pierce OP  @Reply  
     
3 years ago
Any suggestions on corrections?
Maggie M  @Reply  
     
3 years ago
Hi Mark -- Since you completed the Access Developer Series, you might want to review Access Developer 24, 03. Copy Order with Details 2 (27:31). Richard shows you the proper way to do this using recordsets. Good luck.
Mark Pierce OP  @Reply  
     
3 years ago
Thanks for pointing that out, I will go back and review Dev.

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: 4/30/2026 10:27:26 AM. PLT: 1s