Cloning the values from one subform (child control) in a form to another similar form (1 Viewer)

bj05

New member
Local time
Yesterday, 20:41
Joined
May 15, 2017
Messages
3
My requirement is to clone entire form which consist of many subforms and child control in form into similar set for form and subform with child controls.

I am copying the values from one form to another like below:
Form_frm_newForm.controlName.Value = Form_frm_oldForm.controlName

The above code works fine for the controls in the form. However there is one child control in the form which has a subform. The subform is in the datasheet view and may have multiple rows.

I tried the code below to get the values:
Form_frm_newForm.Child285.Controls("Cntrl1") = rs("Cntrl1")
Form_frm_newForm.Child285.Controls("cntrl2") = rs("cntrl2")

rs("Cntrl1") and rs("cntrl2") is values fetched from the query in a loop

The issue is while assigning values in this manner, only the last record is copied and displayed on the form, whereas what I need is as many records as are returned by the query.

I would appreciate if experts could help me with this and I hope I am able to explain my query.
 

Ranman256

Well-known member
Local time
Yesterday, 23:41
Joined
Apr 9, 2015
Messages
4,337
you dont really copy the form, you run an append query using the keys.
The source key tells you where to get the data from, and the target key tells where to put it

qaCloneData:
INSERT INTO
( ClientID )
SELECT
.*, forms!myForm!TargetID AS Expr1
FROM

WHERE (((
.ClientID)=forms!myForm!SourceID));

then refresh the target subform to see the new data:
Code:
docmd.openquery "qaCloneData"
Form_frm_newForm.Child285.requery
 

bj05

New member
Local time
Yesterday, 20:41
Joined
May 15, 2017
Messages
3
I am sorry, but I am new to access and couldn't understand your reply well.

I understood that I can query the data from source form in the target form but didn't get how it can be done.

qaCloneData:
INSERT INTO
( ClientID )
SELECT
.*, forms!myForm!TargetID AS Expr1
FROM

WHERE (((
.ClientID)=forms!myForm!SourceID));

In the example, what is clientID, is it the child control ID? and what the table is referring to?

I am not saving the data unless user clicks on create.

I am basically trying to achieve cloning of the details of an object, so that the user can amend some of the details without having the need to enter the entire information and save the form. On saving a new object will be created in the table. This 'object' has lot of details associated with it, hence subforms in the tabs.

Appreciate if you could share it in detail..

Many thanks for replying :)
 

bj05

New member
Local time
Yesterday, 20:41
Joined
May 15, 2017
Messages
3
I think i understood your reply Ranman256. You are suggesting to insert the data in table and then fetch the results and assign to the subform.
Thanks
 

Ranman256

Well-known member
Local time
Yesterday, 23:41
Joined
Apr 9, 2015
Messages
4,337
The child or the parent ID. They are the same id.
 

Users who are viewing this thread

Top Bottom