Solved

Copy of Control

Posted on 2001-06-04
10
171 Views
Last Modified: 2010-05-02
two forms are opened.
now i want to copy all the controls from form1 to form2.
how to do this?
0
Comment
Question by:anandmehta
10 Comments
 
LVL 22

Expert Comment

by:rspahitz
ID: 6153489
Select all using mouse, choose copy, switch forms, choose paste.
Repeat for all code in the code Window.

0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6153490
Select all using mouse, choose copy, switch forms, choose paste.
Repeat for all code in the code Window.

So, what's the catch?

0
 

Expert Comment

by:MelissaEvans
ID: 6153499
At run time or design time?
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 8

Expert Comment

by:glass_cookie
ID: 6155360
Hi!

Why don't you do this: Duplicate the form instead.  Assuming that the form is called Form2,

Add this code to a module:

Public Sub LoadNewDoc()
    Static lFormCount As Long
    Dim frmD As Form2

    lFormCount = lFormCount + 1
    Set frmD = New Form2
    frmD.Show
End Sub

Then, to make a duplicate of Form2, add this line:

LoadNewDoc

By the way, do make sure that you do not use te line:

LoadNewDoc

IN FORM2 ITSELF or there will be a memory overflow.

That's it!

glass cookie : )
0
 
LVL 8

Expert Comment

by:glass_cookie
ID: 6156431
Oops!  Sorry about 1 mistake.  You CAN USE IT (ie. LoadNewDoc) in Form2 in the previous case, PROVIDED that you do not place it in the Form_Load() procedure or it would cause the new copy to load another new copy and so on and so forth until all your memory is used up.

That's it!

glass cookie : )
0
 

Author Comment

by:anandmehta
ID: 6157029
i want to copy all controls at the run time not at the design time.
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6157043
If might make more sense to simply reference them on on the first form, or make the first form flexible enough to accomodate both.

Why re-invent the wheel if the first wheel has everything you need except one or two things.

The easier way is to build a form that handles both jobs, then set visible=false for those things you don't need at the moment.  Set visible=true when you DO need them.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6157080
Create a custom user control and create instances of it on each form.
0
 
LVL 8

Accepted Solution

by:
glass_cookie earned 100 total points
ID: 6158431
"i want to copy all controls at the run time not at the design time"

This works during runtime.

Public Sub LoadNewDoc()
   Static lFormCount As Long
   Dim frmD As Form2

   lFormCount = lFormCount + 1
   Set frmD = New Form2
   frmD.Show
End Sub

Then, to make a duplicate of Form2, add this line:

LoadNewDoc
'Load a duplicate of ie. Form2
Note: Do not place LoadNewDoc in the Form_Load() procedure.  You could also change "Form2" to whatever form name you have.

That's it!

glass cookie : )
0
 
LVL 8

Expert Comment

by:glass_cookie
ID: 6158436
What would happen would be that an identical Form2 would appear.  Before the frmD.show line, you could add some stuff like frmD.Caption = "Duplicate" or whatever.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Saving history changes to sub form 4 42
Spell Check in VB6 13 112
Prevent user closing word document opened with VB6 6 73
Formula problem with Excel attachment 6 26
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question