Click here to Skip to main content
13,558,743 members
Rate this:
Please Sign up or sign in to vote.
See more:
Look Guys ..
To make my problem clear
I have two forms..
Form 1: 1 textbox and 1 button ( button don't show the name that user enter in txtbox but open form 2)
Form 2: 1 txtbox and button, (in txtbox form 1 user enter name) in this txtbox form 2 the user enter his lastname...The button will show a msgbox wich show up the name and lastname..

how can i do it?

I tried like thi: but it doesn't work out :/

Private Sub Command1_Click()
Static name As Integer
Static lastname As Integer
firstname = txtFirstName.Text
LastName = txtLastName.Text
txtFirstName.Text = Form1.txtFirstName.Text
txtLastName.Text = Form2.txtLastName.Text

both = (Form1.txtFirstName.Text " & & " Form2.txtLastName.Text)
MsgBox (both)

End Sub
Posted 30-Dec-12 4:18am
Updated 30-Dec-12 4:27am
CHill60 30-Dec-12 10:31am
What doesn't work out? What error message or results do you get?
San Dra 30-Dec-12 10:58am
It doesn't display anything..nothing from form 1 only form 2
San Dra 30-Dec-12 10:59am
this code is on command button form 2...while the textboxes in form 1 can't be displayed in form 2
CHill60 30-Dec-12 19:13pm
I'm not surprised this doesn't display anything - it won't even compile ...
Firstly - if this code is on a button on form2 you can't refer to it as Form2.txtLastName.Text - use "Me" instead.
Next - "Static lastname As Integer" then you try to assign txtLastName.Text to it??
why declare "name" as integer or at all
Where is "firstname" declared?
There's more to deal with but get started on fixing the problems I've listed and try again
San Dra 31-Dec-12 7:02am
I don't even know where to declare them, so they can be recognized by all the forms..should I declare them in each form?
San Dra 31-Dec-12 7:07am
All wrong..sorry guys, I've to try all over again
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Applicable for VB.Net, Not applicable For Classic VB...
Public Class Form2
    Public FirstName As String
    Private Sub Command1_Click() Handles Command1.Click
        Dim LastName As String
        Dim Both As String
        LastName = txtLastName.Text  'Replace txtLastName with Name of Your TextBox

        both = (FirstName & LastName)
        MsgBox (Both)
End Sub
End Class

In Form1 Write code as Follows
Public Class Form1
    Private Sub Command1_Click() Handles Command1.Click
        Form2.FirstName = txtFirstName.Text  'Replace txtFirstName with Name of Your TextBox
End Sub
End Class
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


You can hold the value in a variable global type then on second page in messagebox format you can call the the last name value then global value or whatever format you want.

hope it ll help you.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.180515.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100