[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 159
  • Last Modified:

How to re-use controls and code that are on one form on another form?

Hi all,

I have a bunch of combo boxes and code that act as filters for a data grid.  I now want to use an identical implementation (of the combo boxes and associated code) on another form?
Is there a relatively simple way of re-using the controls and code on another form?

Regards,

Leigh
0
LeighWardle
Asked:
LeighWardle
  • 3
  • 2
  • 2
  • +2
1 Solution
 
SethiCommented:
There in no way to implement Control Inheritance or replication in VB. You can however use a freeware named MZTools at www.mztools.com. This will provide you with menu options to copy and paste controls along with the code of the control. This will ease your pain of copying and pasting controls without code.
0
 
Erick37Commented:
During runtime you can create a new instance of your form like this:

Dim frm as Form

Set frm = New Form1 '<<-- Makes a new instance of Form1

frm.Visible = True
'... and so on
0
 
Erick37Commented:
Or if you need to make a duplicate form in your project:

Rename Form1 to Form2
Right Click Form2 in the Project Pane and select Save As...
Save the file to your project directory as Form2.frm

In the Project menu, select Add Form
Select [Existing] then re-add Form1 to your project.

You should now have 2 identical forms in the project.

Make sure that there are no duplicate Public members.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LeighWardleAuthor Commented:
Thanks, Erick37, for your suggestions.

I am sorry I didn't make it clear that I am only trying to replicate what is on part of a form (it could be thought of as consisting of a Frame).

I do not want to duplicate the code - for maintenance reasons.

I note Sethi's comment that there is no way to implement Control Inheritance or replication in VB.

Given the above comments, I would be happy with a solution that involves duplicating the controls, but using just one copy of the code?

Regards,

Leigh
0
 
Mike EghtebasDatabase and Application DeveloperCommented:
Re:> How to re-use controls
Have no input there, but

Re:> and code that are on one form on another form

You can cange 'Private Sub Comman1_Click()' to 'Public Sub Comman1_Click()' to use it via:

Form1.Comman1_Click assuming 'Public Sub Comman1_Click()' is on Form1.

Also, you can transfer the code in such event to a standard module.

Mike
0
 
paulomartinCommented:
Why not create a user defined control with the controls and functions you require. This can be then placed on the forms where you require it.

Paul
0
 
LeighWardleAuthor Commented:
Hi paulomartin,

Can you give me a lead as to how to create a user defined control?

Thanks, Leigh
0
 
paulomartinCommented:
I don not have the English IDE but will try as best i can.
In your IDE Project Explorer, click right mouse button, chose add, then choose user defined control.
You will then get a form which you can place controls on. After you have saved this a new icon will appear in your toolbox. You can then use it like any other control. Look on the net or in text books for some examples. They are easy to use but first try it out with somthing easy. Once you get the hang of it is not too difficult.
0
 
LeighWardleAuthor Commented:
Thanks, eghtebas, for your suggestions.

After looking at the alternative suggestions, I decided the simplest approach was to copy all the controls I needed. I then centralised definitions of the Initialization and Event code for each control.

Thanks to everyone else for your leads,

Regards,

Leigh
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now