How do you pass the data in a field on one form to a field in another form?

Specify formName.fieldName.data

WaltP is correct. You can also call functions, events and methods this way too. For example, if you have a button on form2, and you want to "click" it from a button on form1, you can do something like form2.command1 = true .

stan yost there is a simple way

lets say you want to pass the text feild of text1

1- declare a public variable in the general part of the form like this

public varaiableName as String

2- in the form_load() write

variableName=text1.text

3- you can access this variable from any other form using the form name

lets say you have form2 and you want to pass text1.text which is in form1 to form2 which has a text feild (text2)

you can do that like this:-

text2.text=form1.variableName

- Regarding calling methods You have first to decalre it as public intead of private sub ---> public sub

and u can do the same thing using the form name to call the function

form1.functionName()


I hope this helps

vbmenu_register("postmenu_246662", true);

stan yost there is a simple way

lets say you want to pass the text feild of text1

1- declare a public variable in the general part of the form like this

public varaiableName as String

2- in the form_load() write

variableName=text1.text

3- you can access this variable from any other form using the form name

lets say you have form2 and you want to pass text1.text which is in form1 to form2 which has a text feild (text2)

you can do that like this:-

text2.text=form1.variableName

- Regarding calling methods You have first to decalre it as public intead of private sub ---> public sub

and u can do the same thing using the form name to call the function

form1.functionName()


I hope this helps

vbmenu_register("postmenu_246662", true);

lover99509, is this easier than using form1.text1.text as already recommended?

lover's method is accurate, and will work.... however, it's not good programming style. As Waltp Mentioned, it's easier first off, to reference the object hierarchy, and beyond that, why would you want to use memory space (a variable) to contain information that's ALREADY stored somewhere? That will slow down the program (more processing, and memory usage) and make code a bit more difficult to read....

Thanks, that got me going again.

Hi,

I'm working on something like this and I have the following situation:

I guiding users through a wizard process to select or create various ID's. These ID's are set at the end of the proess when closing the form.
So where I need the ID I start a form in Dialog mode and on closing the new form I set a Public variable in a separate module to the value of this ID.
Within the wizard process I need to do this 2 or three times.
When the dialog form closes the originating form picks up the ID and works with that.

As it now appears the value is not passed between the forms. I cannot refer to the form's variables because at the time I need to pick up the alue the form is already closed.

Using watches I could determine that withn the context of each form the variable doesnot appear to be set.

I refer in the entire project to this variable as GlobalFunctions.SelectedID and in the module GlobalFunction it has been declared as:

Public SelectedID As Long

Unfortunately, the selection process is calledfrom different forms so I cannot define a button that go's back to the originating form that will close the selection form.

Any thoughts on this?

Many thanks in advnce
Hans

I might not understand you completely, but if you are asking what I think you are asking, setting a global variable should work among all forms. I just want to make sure that you are using VB6, and not VB.Net or VB express..... Because I don't believe VB6 has a GlobalFunctions Object.

Thanks fort an answer. I think you understand what I'm doing. I'm programming within MS Acces so VBA. The module GlobalFunctions is my own fabrication.

The problem is it works two or three times in arow and then one time it does not pass the right value.


Greets
ans

Hi
I am working on a payroll program which have 3 forms.
First form has three text box (First name, Surname, Total Hour) and one command button Calculate.
After the user put the info he/she will click calculate button and this will show the second form which display the (firstname, surname, Gross salary, netwage).
I do have another form called frmsummary this form should hold detail of up to 10 person, currently using the code bellow in form two when user click copy info command button on the second form I could only copy 1 person info to form 3. I don’t know what to do any help to get 10 people info coped?

Private Sub cmdcd_Click()
frmsummary.lblfname0 = frmWage.lblfirstname.Caption
frmsummary.lblsname0 = frmWage.lbllastname.Caption
frmsummary.lblgsalary = frmWage.lblGrossSalary.Caption
frmsummary.lblnwage = frmWage.lblNetWage.Caption
frmsummary.Show
End Sub

Thanks for your help in advance
HB25

it's easier first off, to reference the object hierarchy ,and beyond that, why would you want to use memory space (a variable) to contain information that's ALREADY stored somewhere? That will slow down the program (more processing, and memory usage) and make code a bit more difficult to read....

That's simply not the case. Declaring objects as variables saves Visual basic from having to go through the same code again. Once VB has it declared as a variable, it saves processing time.

Hank

Well, I doubt this will get answered since it was so many years ago, but I'll ask anyways. I passed this data TextBox1.Text to my form two text box Old_Name_Display using stanyost's third method, inserting Old_Name_Display = Browser.TextBox1.Text into my Old_Name_Display_Change public sub.

What my program does is after I select a browsed file, it displays in TextBox1.Text. The user then selects "Rename this Project" and form 2 opens. What it SHOULD do is have the text from form1 displayed in my Old_Name_Display text box. What it's ACTUALLY doing is waiting until I type a character before it inputs that data.

Any ideas on how to fix this?

Hi Alyssa, why not start your own thread with your question? You can make a reference to this thread but your own thread will be tailored just to you and it helps search engines too.

Just a suggestion.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.