![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Apr 2002
Location: East Texas
Posts: 38
|
Can someone tell me why this code will not give me three tries
at entering the password. It will only give me one try and then will close. Private Sub CommandButton1_Click() Dim myTries As Integer Dim strPass As String strPass = TextBox1.Text Do Until iTries = 3 If strPass = "password" Then MsgBox "Password Accepted" Sheets("Main").Visible = True Unload Me End End If MsgBox "Incorrect Password" myTries =myiTries + 1 TextBox1.SetFocus Exit Do Loop If myTries = 3 Then Unload Me Application.DisplayAlerts = False ThisWorkbook.Close End Sub Thanks in advance |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
The following line should read myTries not iTries:
Do Until iTries = 3
__________________
Kind regards, Al Chara |
|
|
|
|
|
#3 |
|
New Member
Join Date: Apr 2002
Location: East Texas
Posts: 38
|
That was a typo during the post. The variable does read myTries.
Thanks in advance |
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
myTries =myiTries + 1 should read:
myTries =myTries + 1 Is this just a typo too? Please post your code without typos.
__________________
Kind regards, Al Chara |
|
|
|
|
|
#5 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
Actually your code will not work as it is. You set your strstrPass = TextBox1.Text
How is the user supposed to change the text in the textbox if the macro is running. Everytime you hit the commandbutton mytries looses its scope and returns to 0. You have to declare it as a public variable and throw it in a module. You code needs a lot of help. Post with what you want to do, and I will write something for you (after lunch)
__________________
Kind regards, Al Chara |
|
|
|
|
|
#6 |
|
New Member
Join Date: Apr 2002
Location: East Texas
Posts: 38
|
Al, there is no hurry on this. It is just something I am using to try and teach myself (with the boards help) a little bit of VBA. So what I have is a variable in the workbook open event (which doesn’t work). I am trying to have something that will look at the current date and if this date is later than my Endate then it will load userform1, which is where the password has to be entered. The following is my code so far. Thanks a million for the help.
Private Sub Workbook_Open() Dim EndDate As Date EndDate = Date If EndDate >= "4-20-02" Then UserForm1.Show Sheets("Sheet1").xlVeryHidden Sheets("Main").xlVeryHidden End Sub Private Sub CommandButton1_Click() Dim myTries As Integer Dim strPass As String strPass = TextBox1.Text Do Until myTries = 3 If strPass = "password" Then MsgBox "Password Accepted" Sheets("Main").Visible = True Unload Me End End If MsgBox "Incorrect Password" myTries = myTries + 1 TextBox1.SetFocus Exit Do Loop If myTries = 3 Then Unload Me Application.DisplayAlerts = False ThisWorkbook.Close End Sub |
|
|
|
|
|
#7 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
I created a nice little workbook that gives a good password verification userform/macro that should do what you want. Repy with your email and I will send it to you.
__________________
Kind regards, Al Chara |
|
|
|
|
|
#8 |
|
New Member
Join Date: Apr 2002
Location: East Texas
Posts: 38
|
|
|
|
|
|
|
#9 |
|
New Member
Join Date: Apr 2002
Location: East Texas
Posts: 38
|
Sorry Al I just changed providers the other day my new e-mail is
skyhook@risecom.net |
|
|
|
|
|
#10 |
|
New Member
Join Date: Apr 2002
Location: East Texas
Posts: 38
|
Thanks Al for all the help the code worked great.
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|