Password Userform

F

Freshman

Dear experts,

I want to create an userform with a textbox in which users will input a
password (e.g. PSSW1223). As usual, the characters input will not be shown
but by "********" instead. If the user inputs correctly, a dialogue box
appears stating the password is correct. If the password is incorrect, the
dialogue box will show the wording on the contrary. The user can have 3
trials at the maximum. Please advise what should the VBA code for the user
form. Please kindly advise.

Thanks in advance.
 
P

Per Jessen

Hi
Setup at userform with a textbox and a command button.
First select TextBox1 and in the Properties window (F4), find 'PasswordChar'
and enter *

Then try this code and notice that the dim statement has to be inserted at
the very top of the userform module:

Dim Trial As Long

Private Sub CommandButton1_Click()
TitleStr = "Password check"
If Me.TextBox1.Value = "PSSW1223" Then
msg = MsgBox("Correct password", vbExclamation + vbOKOnly, TitleStr)
Me.Hide
'what to do when password is correct?
Else
Trial = Trial + 1
If Trial < 3 Then
msg = MsgBox("Wrong password, please try again", vbExclamation +
vbOKOnly, TitleStr)
Me.TextBox1.SetFocus
Else
msg = MsgBox("Wrong password, shutting down...", vbCritical +
vbOKOnly, TitleStr)
Unload Me
End If
End If
End Sub

Regards,
Per
 

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