passing information between forms?

how do i do this?
Who is Participating?
Declare the forms variable as public in a module:

Public Form1 as new form1
public Form2 as new form2

in your sub main


'From inside the form1


Now from Form2 you can access Form1 via the public variable:

MsgBox Form1.txtName.Text


In order to access controls from both forms you have to change its Modifiers property to Public.

You can add public variables to the forms and also will be accessible, like:

Public MyVar as string.


Public Module1
        Public Form1 as new Form1
        Public Form2 as new Form2

Public Class Form1
     Public MyVar as string

End class

Public Class Form1
     Public MyVar2 as string

End class
use property get and set .... in form.
create property with public prefix and do not free the form immidiatly then you can get the information like form.textbox1.text
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

by using form objects
'Create a module CT.vb
'Create one shared property for each form
'This example has two forms(Form1 and From2)
Public Class CT
    'For cross talking between forms
    Private Shared m_From1 As From1
    Public Shared Property From1() As From1
            Return m_From1
        End Get
        Set(ByVal Value As From1)
            m_From1 = Value
        End Set
    End Property
    Private Shared m_Form2 As Form2
    Public Shared Property Form2() As Form2
            Return m_Form2
        End Get
        Set(ByVal Value As Form2)
            m_Form2 = Value
        End Set
    End Property
End Class

'To call Form2 from Form1
Dim myForm2 as new Form2

'Tell Form2 who to talk back to and open Form2
'You can also put code here to send to a Form2 control
        CT.Form1 = Me

'You can talk back from Form2 to this instance of Form1
'By putting code in From2 like...
      CT.Form1.Label1.Text = "Blah, Blah"
Fahad MukhtarDistinguished EngineerCommented:
This article has all the necessary code with explanation you want

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.