Help Me Help Me - 6 months ago 18
Vb.net Question

How to send data from Form2 to Form1 into the Form1 TextBox when the button is clicked in VB.NET?

I am trying to send data from Form2 to Form1 but it doesn't work. I will just show the image so that you could understand what the problem is all about.

Here's the image:
Visual scenario of the problem

The problem here is it doesn't work all. I cannot send the data to the Form1. How to make it work?

Here's the VB code for

AddLesseeForm class


Public Class AddLesseeForm 'Form2

'This is the Select Button
Public Sub Button4_SelectLessee_Click(sender As Object, e As EventArgs) Handles Button4_SelectLessee.Click

'Send data to AddData Form. The problem is it doesn't work
Dim OBJ As New AddData

OBJ.LesseeId = TextBox1_LesseeID.Text
OBJ.LesseeName = TextBox2_LesseeName.Text

End Sub
End Class


VB code for
AddData class


Public Class AddData 'Form1

Private Sub Button1_AddLesseeForm_Click(sender As Object, e As EventArgs) Handles Button1_AddLesseeForm.Click
AddLesseeForm.Show()

End Sub

Public Property LesseeId As String
Public Property LesseeName As String


Public Sub AddData_Load(sender As Object, e As EventArgs) Handles MyBase.Load

'Receive data from AddLesseeForm
TextBox1_LesseeId.Text = LesseeId
TextBox2_LesseeNm.Text = LesseeName
End Sub
End Class

Answer

you do not need to create an object of AddData, in VB.Net you can call with only name of Form, like that :

Public Sub Button4_SelectLessee_Click(sender As Object, e As EventArgs) Handles Button4_SelectLessee.Click

        AddData.LesseeId = TextBox1_LesseeID.Text
        AddData.LesseeName = TextBox2_LesseeName.Text
        AddData.UpdateData()
End Sub

and you can create a method for update data in TextBox in AddData Form like this :

Public Sub UpdateData()
    TextBox1_LesseeId.Text = LesseeId
    TextBox2_LesseeNm.Text = LesseeName
End Sub