Entering text in a Form

A

Andrew

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.
 
R

Rick Rothstein \(MVP - VB\)

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

Rick
 
Z

Ze_Al

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top