We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


Creating objects at runtime

zionz asked
Medium Priority
Last Modified: 2010-05-01
Hello, im trying to load multiple forms at runtime, currently im unsing a form as a template loading a copy of it when its needed, like this:

Dim Form2 as Form
Set Form2 = New Form1

It is working but the problem is i can't access the controls, there are some textboxes in form1 that i need to modify, im trying this but it doesn't works:

Dim Form2 as Form
Set Form2 = New Form1


Its possible to do such thing?,thnx in advance.

Watch Question

High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
If you are creating instances of Form1, then declare your variable as such...

   Dim f1 As New Form1       '  <--- "Form1" not "Form"
   f1.Text1 = "Text"

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

It should work with no problems regarding that all the controls anf forms you are using exists
I tried the following and it worked

Dim ff As Form
Set ff = New Form2

ff.Text1 = "dddd"
Yes, it will work, since Form1 is inherited by Form.
But if you use the
dim as Form
set as new Form1 construction, you will not see the intellisense for form1 but for form in, and that will make you think you cannot access it.
While actually, your object is of type Form1 which is a larger object than Form (at least functionality Form + added functionality of Form1)

So you can call  the object you've added yourself.

It's easier to do it the way Idle_Mind did it.. it will show you what you need, but  in other cases, it's easier to create a base object first, and create derived instances later.

objects can be created at run time. Controls, forms, and class modules are examples of objects which you can create both at design time & runtime by creating variable objects and collections.

Use the DIM function to create a variable whose type is that of any registered class.

such as Dim FORM1 as FORM

Variables, defined as an object type are useful because they can refer to an existing object. For example


Look at the use of the Set statement. To establish a variable reference to an object, you cannot simply use the equal sign. You must have to use the SET statement.
There are several reasons why you should be interested in creating a second reference to a control.

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.