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
LVL 1
LeighWardleAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.