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

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

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

nayernaguibCommented:
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
0
gindeCommented:
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.
0
GururagguruAuthor Commented:
Hi,

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

I have the frmx as public
 
   Public frmx as form

 
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.

haricvCommented:
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
0
GururagguruAuthor 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

0
haricvCommented:
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
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
nayernaguibCommented:
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
0
nayernaguibCommented:
??!!!!!!!

_______________

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

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.