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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass a value from one form to another

Status
Not open for further replies.

at51178

Technical User
Mar 25, 2002
587
US
Hi
I am new to vb.net

but I am trying to pass a value from a textbox in form1 to a textbox in form2 but am not having any luck this is the code that I have on the on load event of form2

Dim Form1 as Form1
Me.Text2.text = Form1.Text1.Text


but nothing happens when I open form 2 from a button on form1

Thanks
 
It seems like this question comes up about once per week in this forum. A search should net you an answer.

But anyways, your code won't work. You're declaring a Form1, but not setting it to an instance. Either set Form2's textbox from Form1 when the button is pressed, or modify Form2's constructor to accept a variable for that Textbox, and set it in the Form Load. There are many, many more solutions to accomplish this as well.
 
Use "new". you have to create an instance of a Form1 before you use it.


Dim Form1 as new Form1
Me.Text2.text = Form1.Text1.Text
 
Lorey
thanks for your help
the change I made to my code works fine but I am only able to pass text value of what is in the textboxes property I am not able to type in a value inthe textbox in form1 and then pass that value from form1 to the textbox in form2.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top