Duplicate Form with Subform (1 Viewer)

Takunda Mafuta

Registered User.
Local time
Today, 03:28
Joined
Sep 4, 2019
Messages
13
I'm a newbie to Ms Access and I have tried to follow a lot of content on this subject title but I wasn't successful. Can someone demonstrate for me on the attached sample database.
 

Attachments

  • Duplicate with Subform.accdb
    780 KB · Views: 59

Takunda Mafuta

Registered User.
Local time
Today, 03:28
Joined
Sep 4, 2019
Messages
13
@theDBguy ..... That's exactly what I thought was going to finally work after trying different other things on the internet but it still didn't. Maybe I failed to translate it into my own database, you can try for me please.
 

Takunda Mafuta

Registered User.
Local time
Today, 03:28
Joined
Sep 4, 2019
Messages
13
@theDBguy ..... That's exactly what I thought was going to finally work after trying different other things on the internet but it still didn't. Maybe I failed to translate it into my own database, you can try for me please.
 

Gasman

Enthusiastic Amateur
Local time
Today, 10:28
Joined
Sep 21, 2011
Messages
14,038
There is NO code whatosoever in that database.? :banghead:

What exactly have you tried.?
What if any, error messages did you get?

Please post back with your attempt.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:28
Joined
May 7, 2009
Messages
19,169
duplicate with subform
 

Attachments

  • Duplicate with Subform.accdb
    480 KB · Views: 58

Takunda Mafuta

Registered User.
Local time
Today, 03:28
Joined
Sep 4, 2019
Messages
13
@Gasman...The actual database I tried to use the code is too big to attach on this platform so I made that sample database so that I can get the idea.
 

Takunda Mafuta

Registered User.
Local time
Today, 03:28
Joined
Sep 4, 2019
Messages
13
@arnelgp....it's only duplicating Main form and subform of a form with the Mainfield1 textbox value "Bird".
 

Gasman

Enthusiastic Amateur
Local time
Today, 10:28
Joined
Sep 21, 2011
Messages
14,038
Try this, however you are not going to learn anything if people have to write the code for you?

Code:
Private Sub cmdClone_Click()
    Dim rsParent As DAO.Recordset
    Dim lngID As Long
    Dim lngNewID As Long
    Dim bm As Variant
    Dim strMainField1 As String
    
    lngID = Me.ID
    strMainField1 = Me.MainField1
    Set rsParent = Me.Recordset.Clone
    
    With Me.RecordsetClone

        .AddNew
        !MainField1 = strMainField1
        .Update
        bm = .LastModified
        .Bookmark = bm
        lngNewID = !ID
    End With
    
    CurrentDb.Execute "Insert Into SubTable (MainID, SubField1, SubDield2) " & _
                        "Select " & lngNewID & ", SubField1, SubDield2 From " & _
                        "SubTable Where MainID = " & lngID
    
    Set rsParent = Nothing
    
    Me.Bookmark = bm
            
End Sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 10:28
Joined
Sep 21, 2011
Messages
14,038
@Gasman....Thank you so much, it worked!

Well I did test it before posting. :D

However arnelgp gave you all that code and you were not able or did not want to work out what was wrong.?

That is how you will learn, by undestanding the code.

A lot of the code I have used came from the net and then was modified to suit my purpose. In doing so I slowly understand more and more, slowly being the operative word. ;)

The link that theDBguy posted did it a slightly different way, but should work as it is, once you change the names to suit. However again, you need to understand the code.?

Anyway hopefully you can translate that to your actual DB?

HTH
 

Users who are viewing this thread

Top Bottom