MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Apr 16th, 2002, 09:47 AM   #1
Skyhook
New Member
 
Join Date: Apr 2002
Location: East Texas
Posts: 38
Default

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
Skyhook is offline   Reply With Quote
Old Apr 16th, 2002, 10:09 AM   #2
Al Chara
MrExcel MVP
 
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
Default

The following line should read myTries not iTries:
Do Until iTries = 3
__________________
Kind regards,

Al Chara
Al Chara is offline   Reply With Quote
Old Apr 16th, 2002, 10:28 AM   #3
Skyhook
New Member
 
Join Date: Apr 2002
Location: East Texas
Posts: 38
Default

That was a typo during the post. The variable does read myTries.
Thanks in advance
Skyhook is offline   Reply With Quote
Old Apr 16th, 2002, 11:29 AM   #4
Al Chara
MrExcel MVP
 
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
Default

myTries =myiTries + 1 should read:
myTries =myTries + 1

Is this just a typo too? Please post your code without typos.

__________________
Kind regards,

Al Chara
Al Chara is offline   Reply With Quote
Old Apr 16th, 2002, 11:34 AM   #5
Al Chara
MrExcel MVP
 
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
Default

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
Al Chara is offline   Reply With Quote
Old Apr 16th, 2002, 12:28 PM   #6
Skyhook
New Member
 
Join Date: Apr 2002
Location: East Texas
Posts: 38
Default

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
Skyhook is offline   Reply With Quote
Old Apr 16th, 2002, 01:47 PM   #7
Al Chara
MrExcel MVP
 
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
Default

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
Al Chara is offline   Reply With Quote
Old Apr 16th, 2002, 01:54 PM   #8
Skyhook
New Member
 
Join Date: Apr 2002
Location: East Texas
Posts: 38
Default

Thanks Al
skyhook@flash.net
Skyhook is offline   Reply With Quote
Old Apr 16th, 2002, 02:09 PM   #9
Skyhook
New Member
 
Join Date: Apr 2002
Location: East Texas
Posts: 38
Default

Sorry Al I just changed providers the other day my new e-mail is
skyhook@risecom.net
Skyhook is offline   Reply With Quote
Old Apr 17th, 2002, 11:50 AM   #10
Skyhook
New Member
 
Join Date: Apr 2002
Location: East Texas
Posts: 38
Default

Thanks Al for all the help the code worked great.
Skyhook is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 02:46 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes