PDA

View Full Version : Input box to display as ******



elsuji
10-12-2019, 10:24 AM
Hi ,

I am having the following code.



Dim PassProtect As Variant If pblnEnteredPassword Then GoTo DoStuff
PassProtect = InputBox("Enter password to print calibration certificate soft copy" & vbCrLf, Title:="Control Panel")
If PassProtect = vbNullString Then Exit Sub
If PassProtect = "Boffice" Then
pblnEnteredPassword = True
GoTo DoStuff
Else
MsgBox Prompt:="Incorrect password. Please try again.", Buttons:=vbOKOnly
Exit Sub
End If
DoStuff:

I this when i enter my password it should display as ****** on my Inputbox

Can any one please help me to solve this

paulked
10-12-2019, 11:16 AM
Set the PasswordChar to * in properties.

Oops! That's for a TextBox on a UserForm.

paulked
10-12-2019, 11:22 AM
A quick search (try it!) produced this

https://wellsr.com/vba/2016/excel/mask-your-password-with-this-vba-inputbox/ (https://wellsr.com/vba/2016/excel/mask-your-password-with-this-vba-inputbox/)

elsuji
10-12-2019, 11:29 AM
I had created the user form. But i don't know how to write the code for that.

paulked
10-12-2019, 12:46 PM
You've got the code in your first post!

SamT
10-13-2019, 03:48 AM
You can't do that with an Inputbox; Use a TextBox on a UserForm.


Option Explicit

'Allow multiple passwords
Const PWList As String = "Boffice, Foffice, GoOD1pA$$WOrd:

Dim PW As String
Dim Stars As String

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
'You might need to experiment with Shift

'Save the Keystroke
PW = PW & ChrW(KeyCode)
Stars = Stars & "*"
End Sub

Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
'Display asterisks
TextBox1 = Stars
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
'Finished entering PW
Stars = ""
CheckPW
End Sub

Private Sub CheckPW()
If PW = vbNullString Then Exit Sub
If Instr(1, PWList, PW) Then
PW = ""
DoStuff
Else
MsgBox Prompt:="Incorrect password. Please try again.", Buttons:=vbOKOnly
PW = ""
End If
End Sub

Private Sub DoStuff()
'Fill in the blank
End Sub