?
Solved

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

Posted on 2006-03-22
8
Medium Priority
?
326 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

0
Comment
Question by:Gururagguru
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 14

Expert Comment

by:nayernaguib
ID: 16258266
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
 
LVL 2

Expert Comment

by:ginde
ID: 16258561
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
 

Author Comment

by:Gururagguru
ID: 16265960
Hi,

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

I have the frmx as public
 
   Public frmx as form

 
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Expert Comment

by:haricv
ID: 16266153
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
 

Author Comment

by:Gururagguru
ID: 16266282

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
 
LVL 1

Accepted Solution

by:
haricv earned 750 total points
ID: 16268606
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
 
LVL 14

Expert Comment

by:nayernaguib
ID: 16269118
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
 
LVL 14

Expert Comment

by:nayernaguib
ID: 16269334
??!!!!!!!

_______________

  Nayer Naguib
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

850 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