ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Entering text in a Form (https://www.excelbanter.com/excel-programming/401121-entering-text-form.html)

Andrew[_24_]

Entering text in a Form
 
I wish to input a password using a Form called InputPwd (I'm not using an
InputBox since this can't hide the password typed). The form contains:
- a TextBox called Password and
- a Button called OKbutton

The code associated with OKbutton is:

Private Sub OKButton_Click()
InputPwd.Hide
End Sub

This behaves nearly as I want. To test it I run the following Macro:

Sub Mysub()
InputPwd.Show
MsgBox (InputPwd.Password)
End Sub

This displays the form. I can then type the password which is hidden by *
(the PasswordChar set in the TextBox properties). What I would like is that
pressing Enter at the end of typing the password should behave just as if
I've clicked on the OKbutton. Instead it moves the focus from the TextBox
to the OKbutton, meaning that I have to press Enter twice to submit my
password.

I'm sure there must be a way to get pressing Enter to do what I want.



Rick Rothstein \(MVP - VB\)

Entering text in a Form
 
If you set the Default property for the CommandButton to True, hitting Enter
will automatically select the CommandButton and activate its Click event.

Rick


"Andrew" wrote in message
...
I wish to input a password using a Form called InputPwd (I'm not using an
InputBox since this can't hide the password typed). The form contains:
- a TextBox called Password and
- a Button called OKbutton

The code associated with OKbutton is:

Private Sub OKButton_Click()
InputPwd.Hide
End Sub

This behaves nearly as I want. To test it I run the following Macro:

Sub Mysub()
InputPwd.Show
MsgBox (InputPwd.Password)
End Sub

This displays the form. I can then type the password which is hidden by *
(the PasswordChar set in the TextBox properties). What I would like is
that pressing Enter at the end of typing the password should behave just
as if I've clicked on the OKbutton. Instead it moves the focus from the
TextBox to the OKbutton, meaning that I have to press Enter twice to
submit my password.

I'm sure there must be a way to get pressing Enter to do what I want.



Ze_Al

Entering text in a Form
 
On 14 Nov, 20:35, "Andrew" wrote:
I wish to input a password using a Form called InputPwd (I'm not using an
InputBox since this can't hide the password typed). The form contains:
- a TextBox called Password and
- a Button called OKbutton

The code associated with OKbutton is:

Private Sub OKButton_Click()
InputPwd.Hide
End Sub

This behaves nearly as I want. To test it I run the following Macro:

Sub Mysub()
InputPwd.Show
MsgBox (InputPwd.Password)
End Sub

This displays the form. I can then type the password which is hidden by *
(the PasswordChar set in the TextBox properties). What I would like is that
pressing Enter at the end of typing the password should behave just as if
I've clicked on the OKbutton. Instead it moves the focus from the TextBox
to the OKbutton, meaning that I have to press Enter twice to submit my
password.

I'm sure there must be a way to get pressing Enter to do what I want.



Use a UserForm with a textbox "Password" and a Button "OKbutton". In
the code of the form write:

Private Sub Password_AfterUpdate()
Call OKbutton_Click
End Sub

Private Sub OKbutton_Click()
UserForm.Hide
End Sub

The text box can also have the text as "*" charaters. PasswordChar
propriety

Regards,
José Cruz



All times are GMT +1. The time now is 09:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com