Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating Form1 From Form2 2

Status
Not open for further replies.

dazzer123

IS-IT--Management
Nov 24, 2003
128
GB
I have a form Form1 that opens up Form2 as a modal type form on the click of a button. What I now need to do is update the value of a textbox on Form1 with a value that is entered into a textbox in Form2, again on the click of a button, it should then close Form2.

This used to be fairly straight forward in VB6 but I cant seem to get it to work with VB .Net

Any ideas would be appriciated
 
Suppose you have two textbox and a button on Form1 and you want to update the values of these textbox with values from two textbox on Form2.

'On Button Click Event of Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New Form2
frm.ShowDialog(Me)

Me.TextBox1.Text = frm.TextBox1.Text
Me.TextBox2.Text = frm.TextBox2.Text

frm.Dispose()
End Sub

'On Button Click Event of Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
End Sub

Or you can set DialogResult property of Button on Form2 to OK


 
So how would I use this when somone enters some text into a textbox in Form2 and then presses a button to update the textbox in form1 and close form2

Something like this

'On Button Click Event of Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New Form2
frm.ShowDialog(Me)

End Sub

'On Button Click Event of Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Update Value in textbox on Form1 with value of textbox on Form2
Me.Close()
End Sub
 
Thanks for the help, I got a bit confused for a minute there!! I got it in the end!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top