?
Solved

Creating objects at runtime

Posted on 2006-03-25
4
Medium Priority
?
219 Views
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
Form2.Show

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

Form2.text1="Test"
Form2.Show

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

0
Comment
Question by:zionz
4 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1000 total points
ID: 16291511
If you are creating instances of Form1, then declare your variable as such...

   Dim f1 As New Form1       '  <--- "Form1" not "Form"
   f1.Text1 = "Text"
   f1.Show
0
 
LVL 13

Expert Comment

by:iHadi
ID: 16292997
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"
ff.Show
0
 
LVL 14

Expert Comment

by:PockyMaster
ID: 16294788
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.

0
 
LVL 14

Expert Comment

by:MilanKM
ID: 16308413
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

Set X =NEW FORM1

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.

Thanks
MilanKM
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

621 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