You are here:

Visual Basic/Passing Parameters from one Form to another Form in VB 6


Bruce52 wrote at 2011-06-24 20:15:34
In case you are still in need of an answer: start a new project and add two textboxes (Text1 and Text2) to Form1 and one label(Label1) to Form2. Text1 on Form1 is where you will enter a name, Text2 is used only as a place to accept the focus when you hit the <tab> key. (You could add a command button instead of a second textbox and attach the code to its <click> property if you prefer.) Open the code window for Form1 and insert the following code:

Private Sub Text1_LostFocus()


Form2.Label1.Caption = Form1.Text1.Text

End Sub

Now when you type a name on Form1 into Text1 and press the <tab> key the value will show up on Form2, Label1. If you need to use that value in code for Form2, it can be gotten easily by using a string variable to retrieve it this way:

strName = Label1.Caption

Bruce52 wrote at 2012-06-25 23:43:36
Passing values from one form to another in vb6 is pretty easy. Start a standard exe program with two forms (Form1 and Form2). On Form1 place a text box (Text1) and a command button (Command1). On Form2 place a label (Label1). Open Form1's code window and select "Command1" and "Click" from the two combo boxes at the top of the window. This will add a subroutine named "Private Sub Command1_Click()" to the code window. Place the following in that subroutine:


Form2.Label1.Caption = Text1.Text

That's all there is to it! Now run the program, type something in Text1 and then click on Command1. Form2 will be displayed and the value in Form1 Text1 will be sent to Form2 Label1. I'm pretty sure this would also work in although I have not tried.

Bruce wrote at 2013-08-06 12:55:29
Sorry I didn't find this question a long time ago, but it's very easy to pass data between forms in VB6. Assuming both forms are visible at runtime the following code will do the trick. As you enter some text in the textbox on Form1, the text will be sent to Form2.Label1.Caption without using any variables at all. VB6 is alive and well and still makes great programs.

Private Sub Text1_Change()

 Form2.Label1.Caption = Text1.Text

End Sub

Visual Basic

All Answers

Answers by Expert:

Ask Experts


Frank G. Dahncke


I can answer most questions realating to real-world application programming in Visual Basic .NET (including SQL-Server 7.0 and up). I NO LONGER ANSWER VB6 QUESTIONS. My speciality is GUI/frontend work and API calls. I do not know about Internet, games or graphics programming, just the bread-and-butter stuff. I answer questions in German as well.


Experience: I have been programming BASIC applications professionally for 22 years now (2007), having done most any application type from multimedia CBT to telephone directories to database frontends. Organizations: RA-MICRO Software GmbH

©2017 All rights reserved.