ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to password protect an application (https://www.excelbanter.com/excel-programming/284310-how-password-protect-application.html)

Nathan Gutman

How to password protect an application
 
I have an application for which I want the user to use a password
before being able to use it. I want the user to be able to make up to
three tries before terminating the application.
If I use an InputBox to prompt for the password the user can click
Cancel or Close and can get to the application worksheet without using
any password.
If I use a UserForm with a TextBox to enter the password how can I
display the password TextBox up to three times without unloading and
reloading the UserForm.
If wrong password the user would get a critical MsgBox which when
clicked OK would get, up to three times, immediately back to the
TextBox to re-enter the password.
Thanks for any help,
Nathan

Harald Staff

How to password protect an application
 
Hi Nathan

One way among several. Userform1 code (with a Textbox1 for entry and a CommandButton1
saying "OK" + default=true):

Option Explicit

Public Pwd As String

Private Sub CommandButton1_Click()
Pwd = TextBox1.Text
Me.Hide
End Sub

In a standard module:

Option Explicit

Sub Auto_open()
Dim Count As Long
Dim GoodGuy As Boolean
GoodGuy = False
For Count = 1 To 3
With UserForm1
Select Case Count
Case 1
.Caption = _
"Password please"
Case 2
.Caption = _
"Try again please"
Case 3
.Caption = _
"Last chance:"
End Select
.Show
If .Pwd = _
"Nathan Rules" Then
GoodGuy = True
Exit For
End If
End With
Next
Unload UserForm1
If GoodGuy = True Then
Sheets(1).Visible = True
MsgBox "Yo da man"
Else
Sheets(1).Visible = xlVeryHidden
ThisWorkbook.Save
ThisWorkbook.Close
End If
End Sub



Please don't MsgBox at wrong entries, thay have to be OK'ed away and are all over
extremely annoying. Use a label on the form, it's caption, color or whatever. Anything but
msgboxes.
--
HTH. Best wishes Harald
Followup to newsgroup only please.

"Nathan Gutman" wrote in message
...
I have an application for which I want the user to use a password
before being able to use it. I want the user to be able to make up to
three tries before terminating the application.
If I use an InputBox to prompt for the password the user can click
Cancel or Close and can get to the application worksheet without using
any password.
If I use a UserForm with a TextBox to enter the password how can I
display the password TextBox up to three times without unloading and
reloading the UserForm.
If wrong password the user would get a critical MsgBox which when
clicked OK would get, up to three times, immediately back to the
TextBox to re-enter the password.
Thanks for any help,
Nathan




[email protected]

How to password protect an application
 
John Wilson offers one suggestion in this thread.

http://www.google.com/groups?hl=en&l...ecc1a98&rnum=1

HTH
Paul
--------------------------------------------------------------------------------------------------------------
Be advised to back up your WorkBook before attempting to make changes.
--------------------------------------------------------------------------------------------------------------

I have an application for which I want the user to use a password
before being able to use it. I want the user to be able to make up to
three tries before terminating the application.
If I use an InputBox to prompt for the password the user can click
Cancel or Close and can get to the application worksheet without using
any password.
If I use a UserForm with a TextBox to enter the password how can I
display the password TextBox up to three times without unloading and
reloading the UserForm.
If wrong password the user would get a critical MsgBox which when
clicked OK would get, up to three times, immediately back to the
TextBox to re-enter the password.
Thanks for any help,
Nathan



Nathan Gutman

How to password protect an application
 
Thanks for the suggestions, I will look at them carefully.
There is another twist to that issue.
The worksheet will not require a password for the first 30 days from
the time that it was first opened. After that it will require a
password.
Thanks again,
Nathan
On Wed, 03 Dec 2003 13:01:37 -0700, am wrote:

John Wilson offers one suggestion in this thread.

http://www.google.com/groups?hl=en&l...ecc1a98&rnum=1

HTH
Paul
--------------------------------------------------------------------------------------------------------------
Be advised to back up your WorkBook before attempting to make changes.
--------------------------------------------------------------------------------------------------------------

I have an application for which I want the user to use a password
before being able to use it. I want the user to be able to make up to
three tries before terminating the application.
If I use an InputBox to prompt for the password the user can click
Cancel or Close and can get to the application worksheet without using
any password.
If I use a UserForm with a TextBox to enter the password how can I
display the password TextBox up to three times without unloading and
reloading the UserForm.
If wrong password the user would get a critical MsgBox which when
clicked OK would get, up to three times, immediately back to the
TextBox to re-enter the password.
Thanks for any help,
Nathan




All times are GMT +1. The time now is 08:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com