?
Solved

Copy data from a child form within a MDI

Posted on 2009-03-30
2
Medium Priority
?
304 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

777 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