Solved

Copy data from a child form within a MDI

Posted on 2009-03-30
2
290 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now