1,105,290 Community Members

Help on changing label text

Member Avatar
duelforce1
Newbie Poster
3 posts since Nov 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
zortec
Junior Poster
144 posts since Nov 2009
Reputation Points: 11 [?]
Q&As Helped to Solve: 17 [?]
Skill Endorsements: 0 [?]
 
0
 
Label1.Text = UserNameBox.Text

You will need to declare form variables.

Member Avatar
duelforce1
Newbie Poster
3 posts since Nov 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
AndreRet
Industrious Poster
4,492 posts since Jan 2008
Reputation Points: 362 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 24 [?]
 
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

Member Avatar
vb5prgrmr
Posting Virtuoso
1,670 posts since Mar 2009
Reputation Points: 143 [?]
Q&As Helped to Solve: 299 [?]
Skill Endorsements: 3 [?]
 
0
 

Thanks for the reference AndreRet :)

Member Avatar
AndreRet
Industrious Poster
4,492 posts since Jan 2008
Reputation Points: 362 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 24 [?]
 
0
 

No problem.

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