Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace Textbox Value Using MS Excel VBA

Status
Not open for further replies.

DDTiff

MIS
May 29, 2002
48
0
0
US
Hello,

Can someone please help me ? I really appreciate your time and effort in advance.

I created a form called "Form1" with a textbox called "txtpsswd", and another form called "Form2" with a textbox called "txtnewpsswd" and a command button called "Change".

My goal is to replace the value of "txtpsswd" in "Form1" with whatever value I entered in "txtnewpsswd" of "Form2" when I click the "Change" button.

Can you tell me how you reference a control of a form to another control of another form? I know how to do that in MS Access VBA, but not MS Excel VBA. Once again, thank you for your help.

DDTiff
 
Hi,

Try this...
Code:
Private Sub CommandButton1_Click()
    UserForm2.TextBox1.Text = UserForm1.TextBox1.Text
    UserForm2.Show
End Sub
:)

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884

Skip,
 
Hi Skip,

Thank you for your respond. I think I did not do a good job at explaining what I was looking for, so here is my full story.

I created a form called "Login" with a textbox called "txtEOPW" and a command button called "EOLogin" with the following codes:

Private Sub cmdEOLogin_Click()
Dim psswd As String
psswd = "execoff"
If txtEOPW.Text = psswd Then
rsp = MsgBox("Congratulation! You are a valid user!!", vbOKOnly, "Corporate Login")
If rsp = vbOK Then
EO_Login.Hide
txtEOPW.Text = ""
End If
Else
rsp = MsgBox("Please Try Again", vbOKOnly, "Login Failed")
txtEOPW.Text = ""
txtEOPW.SetFocus
End If
End Sub

I also created another form called "ChangePsswd" with a textbox called "txtnewpsswd" and a command button called "Change".

My goal is that when a user opens up the ChangePsswd form and enter a new password in the "txtnewpsswd" textbox and then click the "Change" button. The value in the "txtnewpsswd" textbox should replace the "execoff" in the "txtEOPW" textbox in the "EOLogin" form.

Once again thank you for your time and help .

DDTiff

 
So what is it that you can't figger out?

BTW, you can set the PasswordChar property in a textbox to echo a character for each keystroke.

:)

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884

Skip,
 
The one thing I have trouble with is that the new value in the "txtnewpsswd" in "ChangePsswd" form did not replace the existing value "execoff" of the "txtpsswd" in the "Login" form.

I tried to replace the value of "txtpsswd" with the new value in the "txtnewpsswd" using the codes you've provide and then click "Change" button, but the "execoff" value did not get replace with the new value in the "txtnewpsswd". Do you know why?

BTW, I did set the Passworchar property.
 
The following codes are for the "Login" Form:

Private Sub cmdEOLogin_Click()
Dim psswd As String
psswd = "execoff"
If txtEOPW.Text = psswd Then
rsp = MsgBox("Congratulation! You are a valid user!!", vbOKOnly, "Corporate Login")
If rsp = vbOK Then
EO_Login.Hide
txtEOPW.Text = ""
End If
Else
rsp = MsgBox("Please Try Again", vbOKOnly, "Login Failed")
txtEOPW.Text = ""
txtEOPW.SetFocus
End If
End Sub

==========================================================
The following code is for changing the existing password "execoff" with the new password (whatever user enters):

Private Sub cmdChange_Click()
'newpsswd of EOChangePsswd form equals to EOPW of
'EO_Login form
EOChangePsswd.txtnewpsswd.Text = EO_Login.txtEOPW.Text
End Sub
 
works for me...
Code:
Private Sub cmdChange_Click()
'newpsswd of EOChangePsswd form equals to EOPW of
'EO_Login form
    EOChangePsswd.txtnewpsswd.Text = EO_Login.txtEOPW.Text
    EOChangePsswd.Show
End Sub
???

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884

Skip,
 
Skip,

So you mean, if you enter "test" into the "txtnewpsswd" and click the "Change" button; the value of the "txtEOPW" value now be "test" instead of "execoff"? Therefore, if next time you open the "Login" form, you should be validated if you enter "test" into the "txtEOPW" instead of "execoff"? Somehow, it doesn't work for me.
 
When you enter a value in txtEOPW, it is placed in txtnewpsswd -- it's YOUR code.

If you want to some other way, just make the assigment the way it ought to be!

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884

Skip,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top