Expand my Community achievements bar.

Copy all subform data and paste into another subform

Avatar

Level 3

Need: I would like to have a button within a subform that allows you to copy all the data (many fields) and then paste it into an empty copy of the subform. Of course the info pasted would fill in all the fields etc.

Reason: We routinely need to move subform data from page 3 in the document to page 11 (example). Currently we insert a new subform and copy/paste each field from 3 to 11 and then delete 3. It would be great to press a copy button in 3 and insert a new subform and paste.into 11.

Is this possible?

3 Replies

Avatar

Former Community Member

Some options (not all):

1) Use global data binding. If you know subform 11 is going to contain the same data as suform 3, name the objects in each subform the same. When you fill the data in subform 3, the objects with the same name in subform 11 will get filled with the same data.

2) Calculate event. For each object in suform 11, use the calculate event to set the value of each object to the value of the subform 3 object.

3) Code. Create a button to manually set the value of the subform 11 objects to the value of the subform 3 objects.

Steve

Avatar

Level 2

Steve's advice is good if this is a runtime question - how a user, filling out a form, can copy data from one section of the form to another.

If this is a buildtime question - how a developer can duplicate a subform to be used elsewhere in the same form or in a different form, you have the following options:

  • Duplicate and move. For one off tasks, select the subform in the Hierarchy pallet, and click Ctrl-D. This creates a copy of the subform, with all its contents, which can then be dragged in the hierarchy to its new position.
  • Cut and paste. For one off tasks, select the subform in the Hierarchy pallet, and click Ctrl-C. Select the new position in the Hierarchy and then in the Design View (it seems odd to select the same object twice in different pallets, but this is required for the copied subform to be pasted into the right place). Click Ctrl-V
  • Fragment. When the exact same subform is going to be used several times in the same and different forms, create a fragment by selecting the subform in the Deisgn View and drag to the Fragment Library pallet. This creates a fragment XDP file. By dragging the fragment onto forms, you are creating links back to the fragment XDP file. Change the fragment and next time you open a form in Designer it will inherit the changes. Fragments cannot be customised for a specific form.
  • Common Object. Similar to fragments, you create a common object by selecting the subform in the Deisgn View and drag to the Object Library pallet. The difference is that when you drag a common object onto a form, it is inserting a copy of the subform. The inserted subform is not linked to the common object and so it can be customised for that form and will not inherit changes to the common object.

Ben Walsh
www.avoka.com

Avatar

Level 3

Thanks for the responses. I wrote code that on click copied the data from the cell into the paste cells and then the paste button copied the data from there to the new place. Works great. Example follows:

//Click event on Copy button

var shot = ShotDesc_subform.SimpleForm.GeneralInfo.ShtTextField1.rawValue

copyarea.ShtTextField1.rawValue = shot

//Click event on Paste button

//Undo in case you pasted by accident

var ushot = ShotDesc_subform.SimpleForm.GeneralInfo.ShtTextField1.rawValue

var pshot = copyarea.ShtTextField1.rawValue

//Undo

undoarea.ShtTextField1.rawValue = ushot

//Paste

ShotDesc_subform.SimpleForm.GeneralInfo.ShtTextField1.rawValue = pshot