1.11M Members

Help on changing label text

 
0
 

Hi, Can someone help please, I really need to get the text on a label to change to what is inputed by the user on the previous login form
The text box where the username is entered is called UserNameBox and the label is called Label1

So whatever is put in the text box i need it to be writen in the label on another form
Any help is really appreiciated

 
0
 
Label1.Text = UserNameBox.Text

You will need to declare form variables.

 
0
 

I tried that but it still isnt working.. :/
You said to declare the variables, what do I have to do for that? Sorry im really new to this

 
0
 

Your easiest way is to do the following -

Form2.Label1.Caption = UserNameBox
Me.Hide 'Or what ever your loginform is calle i.e. frmLogin.Hide

Go to this link where vb5prgrmr gave a solution to a similar problem before

http://http://www.daniweb.com/forums/thread234516.html

Several ways in which to do this and here are three...

1.) (Pass) Add a module and declare a public string variable and when user hits ok, you set the variable with the string you want. Then when the other form loads, that form retrieves the value and displays it in your label.

Help with Code Tags Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
'module codeOption Explicit Dim MyString As String'------------'form that accepts inputOption Explicit Private Sub Command1_Click()MyString = Text1.TextForm2.ShowUnload MeEnd Sub'--------------'main form that displays inputOption Explicit Private Sub Form_Load()Label1.Caption = MyStringEnd Sub'module code
Option Explicit

Dim MyString As String
'------------
'<strong class="highlight">form</strong> that accepts input
Option Explicit

Private Sub Command1_Click()
MyString = Text1.Text
Form2.Show
Unload Me
End Sub
'--------------
'main <strong class="highlight">form</strong> that displays input
Option Explicit

Private Sub Form_Load()
Label1.Caption = MyString
End Sub

2.) (Push) From the form that recieves the input you can directly set the value of the label.

Help with Code Tags Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Option Explcit Private Sub Command1_Click()Load Form2Form2.Label1.Caption = Text1.TextForm2.ShowEnd SubOption Explcit

Private Sub Command1_Click()
Load Form2
Form2.Label1.Caption = Text1.Text
Form2.Show
End Sub

3.) (Pull) When user clicks OK you hide the input form, show the display form and pull the information from the input form.

Help with Code Tags Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
'input formOption Explicit Private Sub Command1_Click()Me.HideForm2.ShowUnload MeEnd Sub'-----------------'Display FormOption Explicit Private Sub Form_Load()Label1.Caption = Form1.Text1.TextEnd Sub'input <strong class="highlight">form</strong>
Option Explicit

Private Sub Command1_Click()
Me.Hide
Form2.Show
Unload Me
End Sub
'-----------------
'Display <strong class="highlight">Form</strong>
Option Explicit

Private Sub Form_Load()
Label1.Caption = Form1.Text1.Text
End Sub

 
0
 

Thanks for the reference AndreRet :)

 
0
 

No problem.

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: