Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Copy data from a child form within a MDI

Posted on 2009-03-30
2
Medium Priority
?
305 Views
Last Modified: 2012-05-06
I have two forms in a parent MDI. I want to copy the value displayed in Textbox1 of Form1 to Textbox1 of Form2.
By not using MDI, the code Me.Textbox1.Text=Form1.Textbox1.Text worked fine. But when I run the forms using MDI, it did not work.
How do I refer Form1 with a MDI form.

Thanks.

Ed
0
Comment
Question by:MINDSUPERB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 24020667
"By not using MDI, the code Me.Textbox1.Text=Form1.Textbox1.Text worked fine."

This worked because you were accessing the "default instance" of Form1...most likely it was the startup form in that test?

If you will only ever have ONE instance of each MdiChild form, then use the default instances for each child form.  If you need multiple instances of a child then this option is out.  To use the default instance, just use the NAME of the form, WITHOUT ever using the "new" keyword:

    ' ...in the MdiParent...
    Form1.MidParent = Me ' <-- the "new" keyword was NOT used
    Form1.Show()

    ' ...then from ANYWHERE...you can access the other child forms by NAME:
    Me.Textbox1.Text=Form1.Textbox1.Text

Otherwise, you could iterate the MdiChildren() collection until you find a match:

    ' ...from within an MdiChild:
    For Each frm As Form In Me.MdiParent.MdiChildren
        If Typeof frm Is Form1 Then
            Dim f1 As Form1 = DirectCast(frm, Form1)
            Me.TextBox1.Text = f1.TextBox1.Text
            Exit For
        End If
    Next

But this has limited use if you have multiple instances since you would know which one is the one you wanted.
0
 
LVL 19

Author Closing Comment

by:MINDSUPERB
ID: 31564350
Thanks. You give me both: a solution of my problem and a best learning.
0

Featured Post

Independent Software Vendors: 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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

610 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