Hiding text for passwords using InputBox?

sagain2k

Board Regular
Joined
Sep 8, 2002
Messages
94
I have the following code to prompt the user to enter a password. Is there a way to make the displayed input hidden in the dialog box as the user enters the text, such as looking like the ***** characters for typical password entry? Thanks!

PassWdToOpen = InputBox("Enter Password: ")
If PassWdToOpen = "" Then
End
End If
If PassWdToOpen <> "testpassword" Then
MsgBox ("INCORRECT PASSWORD...try again and be sure Caps Lock is off since " & _
"the password IS case sensitive.")
Exit Sub
End If
 
Thanks, Ivan...and to Juan for a solution. His solution creates the UserForm, using a Class Module to do so and refering to the function. Will you always have to use a function and class module to do this? Is the only way involve creating a custom userform, or is there still some way to control the InputBox so accomplish the same thing? I'm trying to minimize how many different areas the code must reside.

Someone mentioned a different UserForm method, but didn't include an explanation. Anyway, this "class module" method will work, but I'm curious about other methods as well. Thanks for passing this along, and Juan, thanks for all your extensive efforts in this valuable forum!

--Ray
 
Upvote 0
To answer one of your questions.

Juan created that class module and Userform that's generated to look like an InputBox, but with the added functionality that you can't see the characters. He did this because you have very limited control over the InputBox used in VBA. You have no control over the look and feel of the Inputbox. So, no, there's no way to mask the password characters in a regular inputbox.
 
Upvote 0
On 2002-10-04 14:59, sagain2k wrote:
...Someone mentioned a different UserForm method, but didn't include an explanation. Anyway, this "class module" method will work, but I'm curious about other methods as well. Thanks for passing this along, and Juan, thanks for all your extensive efforts in this valuable forum!

--Ray

First, thanks to Ivan and Mark for the link and explanation, I really like that class module.

Now, to answer Ray's question, the "other" method is basically the same, but you have to do it at design time, that is, you have to create the userform, the buttons, the textbox, change the properties, do the code, etc. The good news is that you can customize it a lot more, the "bad" news, is that you have to take a little more time to do this.

_________________
Regards,

Juan Pablo G.
MrExcel.com Consulting
This message was edited by Juan Pablo G. on 2002-10-04 16:08
 
Upvote 0
Juan..thanks for the added explanation..so does that mean you just have a custom form in the Forms module, and then don't need to create a Class Module?
 
Upvote 0
Juan...I've inserted a form (called PassWdBox) and it has the following code associated with it:

Public MyText As Variant
Private Sub BCancel_Click()
MyText = False: Me.Hide
End Sub
Private Sub BOk_Click()
MyText = TextBox1.Value: Me.Hide
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then Cancel = True: MyText = False: Me.Hide
End Sub

I created another proceedure "PassWdBoxShow" stored in Module1 to show the form:

Sub PassWdBoxShow()
PassWdBox.Show
End Sub

This works fine the first time I use it, allowing me to enter the password and masking the characters as the "*" symbol.

But when I try running it again right after using it (I created a toolbar button to run it as a test...clicking it the first time, then clicking it again), it displays showing the previous * symbols, and the textbox does not have the focus automatcially nor are those * symbols highlighted.

I've run into this problem before with custom forms: How to set the focus each time you show the form so that the desired text box either has a blinking cursor in it, or any default text that is there is already highlighted ready for you to type in new text.

I've tried using the TextBox1.SetFocus
command but that doesn't seem to do it. Perhaps I'm not placing it in the appropriate subprocedure. I've even tried using the Sendkeys method to enter the Tab key to get the focus and cursor in there, but that isn't a desireable solution.

Any suggestions on how best to always have textbox1 either have a blinking cursor or highlighted text in it with focus ready for entering whenever a form is shown? Thanks!!

--Ray
 
Upvote 0

Forum statistics

Threads
1,226,824
Messages
6,193,164
Members
453,778
Latest member
RDJones45

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top