Solved

Add text to Second form

Posted on 2004-10-15
3
306 Views
Last Modified: 2010-04-23
How can I add text to another form without re-showing it?
I can do it if I use the following code


Dim t As New Form2
        t.TextBox1.Text = "test"
t.show


But the form is already open so I don’t want to reshow it

I have tried

Dim t As New Form2
        t.TextBox1.Text = "test"
me.close

With no success
0
Comment
Question by:davidrichardson
[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
3 Comments
 
LVL 4

Accepted Solution

by:
gdexter earned 125 total points
ID: 12322903
You can not do this by creating a new instance of Form2. You need to pass a reference to the current instance of Form2 to the other form through a property.

Does Form2 open the active form that needs to adjust the text?

If you are not using MDI you can do something like this:

Public Class OtherForm
   'declare a reference variable
   private _Form2 as Form2
 
   Public WriteOnly Property MyForm2() as Form2
      Set(ByVal Value as Form2)
         Me._Form2 = Value
      End Set
   End Property

   Public Sub WriteToForm()
      Me._Form2.TextBox1.text = "test"
   End Sub

End Class

'When you open the OtherForm object from Form2 you pass a refence to itself
'In Form2

Public Sub LoadOtherForm
   
   Dim frm as New OtherForm
   frm.MyForm2 = Me
   frm.Show

End Sub

If you are using MDI this functionality is provided through the 'MDIParent' Property


 


   
 






0
 
LVL 7

Author Comment

by:davidrichardson
ID: 12323162
form 2 does open the active form, when i run WriteToForm() i get the following error

Object reference not set to an instance of an object

On line Me.frmscaninput.TextBox1.Text = "test"

Copy of full code used below

    Private frmscaninput As frmscaninput

    Public WriteOnly Property MyForm2() As frmscaninput
        Set(ByVal Value As frmscaninput)
            Me.frmscaninput = Value
        End Set
    End Property

    Public Sub WriteToForm()
        Me.frmscaninput.TextBox1.Text = "test"
    End Sub


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        WriteToForm()

    End Sub
0
 
LVL 7

Author Comment

by:davidrichardson
ID: 12323300
my mistake i didnt as the load form cade properly

Thanks

Dave
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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