We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


VB6 - I have a dynamically created form. I cannot access the variables from the dynm created form to a non-dynamic form!

Gururagguru asked
Medium Priority
Last Modified: 2010-04-17
Dear All

  I have two forms in my project Form1 and Form2

 I have created a form dynamically to view through menus. It works fine.

 Set frmx = Forms.Add(form1)

 Here i can see form1 in run time. Within form1 i am opening form2.
 ie  on a command click

I works fine. But now from form2 i need to send a variable to populate into Frmx which is dynamically created.

  eg. Form2 - i have a variable  called  empname
       In frmx (dynamically created) have a text box TxtEmpname

      now during run time in form2 if i use
           frmx.txtempname = empname

   I get the error message object not found. Ie vb cannot find frmx.

Please help

Watch Question

The following piece of code can be used to dynamically get a reference to a control:


For i = 0 To frmx.Controls.Count - 1
  If frmx.Controls(i).Name = "TxtEmpname" Then
    frmx.Controls(i).Text = "Hello"
  End If
Next i



  Nayer Naguib

You can do it in many way.
1. Raise event from second form and catch in it first.
2. Create Public methog on form1 and call that method from form2.



When i try this i still get the error! object required

I have the frmx as public
   Public frmx as form



You need to get handle of the correct form to call variables in that

So if you have the following code in menu click event
 Set frmx = New Form1

instead of
 Set frmx = Forms.Add(form1)

Hope this works



Now, the next issue is the form name is stored in a variable and i am picking it

like this  Set frmX = Form.Add(strFormName)

in this case how do i

set frmx = new strformname

I have created a simple vb project for you
http://hitmarket.net/ex/DynamicForms.zip download it and pls test.

I hope this will solve your problem

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

Ask the Experts
You need to refer to frmx using a fully qualified name.
For example, if frmx is declared as public in a form called frmMain, then you can refer to frmx as frmMain.frmx.


  Nayer Naguib


  Nayer Naguib
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.