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!

Duplicate Form and Table

Status
Not open for further replies.

robdunfey

Technical User
Apr 26, 2002
110
GB
I have a form(FormA) that displays data from a table(TableA). I want to click a button that copies both the form and the table, the copies are called FormB & TableB, all the text boxes on FormB display data from TableB. The result is you can make changes to the data in TableB e.g. add records, and it does not effect TableA or FormA. Ideally I would like to create FormA using the wizard.

Does anybody know where I can find samples of code that show you how to copy forms and tables, and set the control source?

Any help very much appreciated.

Rob
 
This is not perfect, but it works.

Put this code on the OnOpen event of FormA:

==========
If Me.NAME = "FormA" Then
Me.RecordSource = "TableA"
ElseIf Me.NAME = "FormB" Then
Me.RecordSource = "TableB"
End If
==========

Put this code on the button click on the FormA button:

==========
DoCmd.CopyObject , "TableB", acTable, "TableA"
DoCmd.CopyObject , "FormB", acForm, "FormA"
DoCmd.OpenForm "FormB"
==========

This will copy the objects, and when you open FormB, it's recordsource will be set to TableB. Jim Lunde
compugeeks@hotmail.com
We all agree your theory is crazy, but is it crazy enough?
 
Use this Sql statement to create your copied table
Code:
SELECT * INTO TableB FROM TableA[\code]

Then you can declare a variable like this:

[code]dim Form2 as new Form_Form1[\code]

and set it's recordsource property like:

[code]Form2.recordsource = "SELECT * FROM Table2"[\code]

and don't forget:

[code]Form2.Visible = True[\code]

This will open up another copy of Form1 with all the same code, properties etc.
Declare the variable with scope such that the form will stay open for as long as you want. Possibly declare it globally if you think that's best. 
Don't forget to drop Table2 when you're finished with it. Durkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top