Solved

Copy data from a child form within a MDI

Posted on 2009-03-30
2
301 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 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Title # Comments Views Activity
Open a link in vb.net 2 27
Crystal reports login after closing form 3 40
Assign a value in Excel V-Basic 3 30
Broken .resx file generating errors 18 26
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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

730 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