Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy a Form and its’ subform data

Status
Not open for further replies.

DaveMac

Technical User
Apr 9, 2000
161
US
I have a form and a subform. The form is a work order type form and the subform are the expected tasks. I would like to make a command button that when clicked copies the form and its’ subform’s data. The link field is called WO_ID. So how do you code a copy of the me.form and the me.subform and add resulting new WO_ID to the childs WO_ID fields that are being copied?


Thanks!!!!
 
How are ya DaveMac . . .

What are you going to do with the copy?

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thanks for the help! I am going to use it as a new record and work order. So basically When work orders are completed they are complete. If the next day the next month what ever when we want the same record set in the parent and child tables I want to automate the copy. Right now it is a copy of the parent and a copy of the child pasted in the form then go and manually change all the WO_IDs to the new parent and we are there.
 
DaveMac . . .

In your mainform put a question mark [blue]?[/blue] ([red]no quotations plwase[/red]) in the [blue]Tag[/blue] property of the textboxes of interest. Do the same for the subform. Now copy/paste the following to your command button ([blue]the button has to be on the mainform![/blue]):
Code:
[blue]   Dim sfrm As Form, ctl As Control, DQ As String
   
   Set sfrm = [[purple][B][I]YourSubFormName[/I][/B][/purple]].Form
   DQ = """"
   
   [green]'Form![/green]
   If Not Me.NewRecord Then
      For Each ctl In Me.Controls
         If ctl.Tag = "?" Then
            ctl.DefaultValue = DQ & ctl & DQ
         End If
      Next
   End If
      
   [green]'subForm[/green]
   If Not sfrm.NewRecord Then
      For Each ctl In sfrm.Controls
         If ctl.Tag = "?" Then
            ctl.DefaultValue = DQ & ctl & DQ
         End If
      Next
   End If[/blue]
Give it a whirl and let me know . . .

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
AceMan1 thanks for the help! I set the code and here is what I am getting.

can't find the field '|' referenced in your expression

I do not think it is part of the sub form code since I tried to comment it out and see if I still get this and I do. I do not see many vertical bars in windows applications so I have no idea where to begin.

What are you thoughts?

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top