View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Per Jessen Per Jessen is offline
external usenet poster
 
Posts: 1,533
Default Password Userform

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


"Freshman" skrev i meddelelsen
...
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.