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

x

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

Gururagguru
Gururagguru asked
on
Medium Priority
345 Views
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)
 frmx.Show

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

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

Comment
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

Commented:
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.

Author

Commented:
Hi,

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

I have the frmx as public
 
   Public frmx as form

 

Commented:
Hi

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
 frmx.Show

instead of
 Set frmx = Forms.Add(form1)
 frmx.Show

Hope this works
Thanks

Author

Commented:

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

Commented:
Hi
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
Thanks
Hari

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.

OR

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.