Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 10-29-2019, 04:39 AM   #1
Takunda Mafuta
Newly Registered User
 
Join Date: Sep 2019
Location: Zimbabwe
Posts: 13
Thanks: 5
Thanked 0 Times in 0 Posts
Takunda Mafuta is on a distinguished road
Duplicate Form with Subform

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.
Attached Files
File Type: accdb Duplicate with Subform.accdb (780.0 KB, 6 views)

Takunda Mafuta is offline   Reply With Quote
Old 10-29-2019, 07:06 AM   #2
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 6,653
Thanks: 58
Thanked 1,459 Times in 1,440 Posts
theDBguy has a spectacular aura about theDBguy has a spectacular aura about
Re: Duplicate Form with Subform

Hi. Just curious, have you tried this?
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is offline   Reply With Quote
Old 10-30-2019, 02:05 AM   #3
Takunda Mafuta
Newly Registered User
 
Join Date: Sep 2019
Location: Zimbabwe
Posts: 13
Thanks: 5
Thanked 0 Times in 0 Posts
Takunda Mafuta is on a distinguished road
Re: Duplicate Form with Subform

@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 is offline   Reply With Quote
Old 10-30-2019, 02:16 AM   #4
Takunda Mafuta
Newly Registered User
 
Join Date: Sep 2019
Location: Zimbabwe
Posts: 13
Thanks: 5
Thanked 0 Times in 0 Posts
Takunda Mafuta is on a distinguished road
Re: Duplicate Form with Subform

@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 is offline   Reply With Quote
Old 10-30-2019, 02:36 AM   #5
Gasman
Enthusiastic Amateur
 
Gasman's Avatar
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 4,562
Thanks: 442
Thanked 847 Times in 818 Posts
Gasman is a jewel in the rough Gasman is a jewel in the rough Gasman is a jewel in the rough
Re: Duplicate Form with Subform

There is NO code whatosoever in that database.?

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

Please post back with your attempt.
__________________
Access novice. Sometimes trying to give something back.
Access 2007

Please, please use code tag # when posting code snippets

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is offline   Reply With Quote
Old 10-30-2019, 03:13 AM   #6
arnelgp
error reading drive A:
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 8,569
Thanks: 68
Thanked 2,745 Times in 2,630 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: Duplicate Form with Subform

duplicate with subform
Attached Files
File Type: accdb Duplicate with Subform.accdb (480.0 KB, 3 views)
__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
Old 10-30-2019, 10:37 PM   #7
Takunda Mafuta
Newly Registered User
 
Join Date: Sep 2019
Location: Zimbabwe
Posts: 13
Thanks: 5
Thanked 0 Times in 0 Posts
Takunda Mafuta is on a distinguished road
Re: Duplicate Form with Subform

@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 is offline   Reply With Quote
Old 10-30-2019, 10:40 PM   #8
Takunda Mafuta
Newly Registered User
 
Join Date: Sep 2019
Location: Zimbabwe
Posts: 13
Thanks: 5
Thanked 0 Times in 0 Posts
Takunda Mafuta is on a distinguished road
Re: Duplicate Form with Subform

@arnelgp....it's only duplicating Main form and subform of a form with the Mainfield1 textbox value "Bird".
Takunda Mafuta is offline   Reply With Quote
Old 10-31-2019, 02:33 AM   #9
Gasman
Enthusiastic Amateur
 
Gasman's Avatar
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 4,562
Thanks: 442
Thanked 847 Times in 818 Posts
Gasman is a jewel in the rough Gasman is a jewel in the rough Gasman is a jewel in the rough
Re: Duplicate Form with Subform

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
__________________
Access novice. Sometimes trying to give something back.
Access 2007

Please, please use code tag # when posting code snippets

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is offline   Reply With Quote
Old 10-31-2019, 03:06 AM   #10
Takunda Mafuta
Newly Registered User
 
Join Date: Sep 2019
Location: Zimbabwe
Posts: 13
Thanks: 5
Thanked 0 Times in 0 Posts
Takunda Mafuta is on a distinguished road
Re: Duplicate Form with Subform

@Gasman....Thank you so much, it worked!
Takunda Mafuta is offline   Reply With Quote
Old 10-31-2019, 03:28 AM   #11
Gasman
Enthusiastic Amateur
 
Gasman's Avatar
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 4,562
Thanks: 442
Thanked 847 Times in 818 Posts
Gasman is a jewel in the rough Gasman is a jewel in the rough Gasman is a jewel in the rough
Re: Duplicate Form with Subform

Quote:
Originally Posted by Takunda Mafuta View Post
@Gasman....Thank you so much, it worked!
Well I did test it before posting.

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

__________________
Access novice. Sometimes trying to give something back.
Access 2007

Please, please use code tag # when posting code snippets

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is offline   Reply With Quote
Reply

Tags
form access , form button , vba

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Duplicate form and subform Access Fun Forms 3 03-01-2017 06:27 PM
[SOLVED] Duplicate Button for Form/Subform/Subform Harry Paraskeva Forms 2 09-09-2013 03:58 AM
Duplicate Form/SubForm/Subform within subform Grooz13 Modules & VBA 0 02-28-2012 06:40 AM
Duplicate a form and subform using an autonumber paul young Modules & VBA 2 06-04-2006 01:22 AM




All times are GMT -8. The time now is 02:21 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World