Hi there.
I'm having trouble passing variables between Forms. Let me explian my self by an example.
I have a Form1, the user types a "Client ID" in a textbox if it's not a valid one, it opens a Form2 in which the user selects the correct "Client ID", once selected he presses an OK button.
And there comes the porblem.. it opens a new Form1 with the Client ID that he selected from Form2, but I still have the first Form1 opened.
I have two Form1 opened...

I which to keep the original Form1, but with the value sent from Form2..

I'm using this code:

Code in Form1

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim obj As New Form2
        obj.passedtext = TextBox1.Text

    End Sub

Code in Form2

Public Class Form2

    Private _passedtext As String
    Public Property [PassedText]() As String
            Return _passedText
        End Get
        Set(ByVal Value As String)
            _passedText = Value
        End Set
    End Property

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label1.Text = _passedtext
    End Sub
4 Years
Discussion Span
Last Post by zeqe

U can directly use the text boxes instead of using property

just giving an example

If I want a value from form1 to form2 then I use following way

code in form1


In this way it wont open a new form....In your code u have used

Dim obj As New Form2

so u are getting a new form...just pass variables with form instead of creating property and also u can call the hide() and show() methods of the form

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.