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

text from one form to another 1

Status
Not open for further replies.

Svanholm

Programmer
Jul 11, 2007
31
0
0
DK
This should be simple. I just have not figured it out:

How can I copy contents from one textbox on one form to a textbox on another form. The second form was opened by first form.

I also want to do it the other way: from the second form to the first.

I am a newbie, so it's probably very simple. I just did not come across it in my VB-books.

I work in vb5 by the way

Thx in advance


 
'In the calling form:
Dim mySubForm As VB.Form
Set mySubForm = New Form2

mySubForm.Show




mySubForm.Text1.Text = Me.Text1.Text
 
SBerthold, if the form, Form2, is already loaded and open, won't this code create a new instance?

 
Yes of course.

Figurinng Svanholm is a beginner, my point was to show how to load the subform and assign a value to a control which is on it.
More so was to show that the code was in the calling form, and "Me." referred to the form this code was on.
Therefore I moved the last line further down as to avoid confusion, but now see that it could cause confusion.


If the form is already loaded, then just use the last line in the "Parent/Calling" form and replace the "mySubForm" with the form name in question.
 
Thx guys

Really appreciate

Am gonna try that out.


 
SB's code is of course fine, but SVanholm, since you're a newbie, I'd like to also make clear that you're not required to create any variables to accomplish the task at hand. Assuming two forms, form1 and form2, both loaded (you can put the line form2.show in form1's load event and both forms will be loaded and visible), and each with a text box text1, you can put form2's text into form1's textbox with the following:
Code:
form1.text1.text = form2.text1.text

Also, vbsun, if you don't want to create a new instance, you can change SB's code as follows:
Code:
'Set mySubForm = New Form2
Set mySubForm = Forms(1)
(assuming the second form loaded is the one you're looking for) and you will instead reference the existing instance.
 
BobRhodes,

I think that is just the simple answer I am looking for.

Thanks for levelling with a "simple-minded" newbie.

Will test it shortly

Thanks a bunch - also to you other guy's advice.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top