When a password is entered...

jimmywanna

Board Regular
Joined
Mar 18, 2002
Messages
182
I have a macro which runs to make the user enter a password after a control button is pushed. It works perfectly, my only problem is when the password is entered the text being typed is visible. Is there any way of the text appearing as "******" or "XXXXXXX" so as anyone around cannot see the password?

thanks in advance guy's

jim

here is the macro:

Sub UNHIDEFORM()
'
' UNHIDEFORM Macro
' Macro recorded 30/01/2004 by gibsonj
'

'
Dim Pass, Msg As String
Dim Ans As Byte
Msg = "Wrong Password" & vbCrLf
Msg = Msg & "Try Again ?"
Password = "PRESLEY" ' Case sensitive
Pass = "xxx"

Do Until Pass = Password
Pass = InputBox("Enter Password", "Password")
If Pass = "" Then ActiveWorkbook.Close SaveChanges:=False
If Pass <> "PRESLEY" Then Ans = MsgBox(Msg, vbCritical + vbYesNo, "Password")
If Ans = vbNo Then ActiveWorkbook.Close SaveChanges:=False
Loop
Range("A1").Select

Columns("B:J").Select
Selection.EntireColumn.Hidden = False
Range("E2:F2").Select
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
You will need a userform with a textbox. You can then set the PasswordChar property to * or whatever.
 
Upvote 0
Thanks for the help guy's

I have made a user form, and changed the properties, will the code for the macro i have work the same for the user form?

I haven't had much luck with user forms in the past, i have given up on them usually.

For instance, underneath the text box i have made an "OK" command button, can i paste the relevent piece of code from my original macro?

jim
 
Upvote 0
Success!
I have made the userform work!
BUT
If the correct password is entered it does as it should, If the password is incorrect the message box appears asking to try again, If i click yes the message box reappears instantly, when i click no the whole book closes.

What do i have to change so when yes try again is clicked the curseor goes back to a cleared textbox on the userform?

Any help is really appreciated chaps.

code:

Private Sub CommandButton1_Click()
Dim Pass, Msg As String
Dim Ans As Byte
Msg = "Wrong Password" & vbCrLf
Msg = Msg & "Try Again ?"
Password = "PRESLEY" ' Case sensitive
Pass = "xxx"

Do Until Pass = Password
Pass = TextBox1.Text
If Pass = "" Then ActiveWorkbook.Close SaveChanges:=False
If Pass <> "PRESLEY" Then Ans = MsgBox(Msg, vbCritical + vbYesNo, "Password")
If Ans = vbNo Then ActiveWorkbook.Close SaveChanges:=False
Loop
Range("A1").Select

Columns("B:J").Select
Selection.EntireColumn.Hidden = False
Range("E2:F2").Select
UserForm2.Hide
End Sub
 
Upvote 0
ME AGAIN!!!

I think I know which part of the above code I have to change, alas i do not know what to write:

Do Until Pass = Password
Pass = TextBox1.Text
If Pass = "" Then ActiveWorkbook.Close SaveChanges:=False
If Pass <> "PRESLEY" Then Ans = MsgBox(Msg, vbCritical + vbYesNo, "Password")
If Ans = vbNo Then ActiveWorkbook.Close SaveChanges:=False
If Ans = vbYes Then..............
Loop

After the "then" I need it to say TextBox1.select, is this correct, as whenever i have tried i keep loosing what i have just done as the workbook closes!

thanks guys.
 
Upvote 0
Nope, It's no good. I have searched through all of the available help and i am still clueless.

Where do i go from here.

I want the message box to hide, and the cursor to return to the text box in the form.

Surely this is possible isn't it?

o_O

jim
 
Upvote 0
Hi jim,

Is this the sort of thing you mean?
Code:
Private Sub CommandButton1_Click()
    
    Const Password As String = "PRESLEY"    ' Case sensitive
    Dim Pass As String, Msg As String
    Dim Ans As Integer
    
    Msg = "Wrong Password" & vbCrLf & "Try Again ?"
    Pass = TextBox1.Text
    
    If Pass = "" Then ActiveWorkbook.Close SaveChanges:=False
    
    If Pass <> "PRESLEY" Then
        Ans = MsgBox(Msg, vbCritical + vbYesNo, "Password")
        If Ans = vbNo Then
            ActiveWorkbook.Close SaveChanges:=False
        Else
            TextBox1.Text = ""
            TextBox1.SetFocus
        End If
    Else
        Unload Me
    End If
    
End Sub
HTH
 
Upvote 0
Fantastic.

Thanks Guy's

I am so close to almost understanding this stuff, with the help of you guy's I wiil one day actually know what I'm doing.

Thanks again

Jim
:pray:
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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