Solved

Copy data from a child form within a MDI

Posted on 2009-03-30
2
300 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
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

856 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