Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Password - 3 chances and **off


I have put together a macro for entering a password. How do I go about
putting in a loop or some other ingenious bit of code so that you only
get 3 chances before you get booted out.

My code is attached to a very simple form and is as follows:

Public Sub PasswordOK_Click()
Dim Password As String
Dim count As Integer
Password = ""
If TextBox1 = Password Then
Personal_Details.Show
Unload Me
End If

If TextBox1 < Password Then
TextBox1 = ""
Label1.Visible = True
PasswordOK.Visible = False
PasswordCancel.Visible = False
Application.Wait Now + TimeValue("00:00:02")
Label1.Visible = False
PasswordOK.Visible = True
PasswordCancel.Visible = True
End If
End Sub
Private Sub PasswordCancel_Click()
Unload Me
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
Beep
End If
End Sub


--
Shake
------------------------------------------------------------------------
Shake's Profile: http://www.excelforum.com/member.php...o&userid=28577
View this thread: http://www.excelforum.com/showthread...hreadid=483069

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Password - 3 chances and **off

Before you get to the 3 chances bit, you have some more basic problems
to address.

Look at the code
Password = ""
If TextBox1 = Password Then

Unless TextBox1 is empty your test will always fail since the expected
password is the zero length string.

Also, and depending on what you mean to do
Personal_Details.Show
Unload Me

may not really be what you want. Instead, it might be more appropriate
to use
me.hide
personal_details.show

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...

I have put together a macro for entering a password. How do I go about
putting in a loop or some other ingenious bit of code so that you only
get 3 chances before you get booted out.

My code is attached to a very simple form and is as follows:

Public Sub PasswordOK_Click()
Dim Password As String
Dim count As Integer
Password = ""
If TextBox1 = Password Then
Personal_Details.Show
Unload Me
End If

If TextBox1 < Password Then
TextBox1 = ""
Label1.Visible = True
PasswordOK.Visible = False
PasswordCancel.Visible = False
Application.Wait Now + TimeValue("00:00:02")
Label1.Visible = False
PasswordOK.Visible = True
PasswordCancel.Visible = True
End If
End Sub
Private Sub PasswordCancel_Click()
Unload Me
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
Beep
End If
End Sub


--
Shake
------------------------------------------------------------------------
Shake's Profile:
http://www.excelforum.com/member.php...o&userid=28577
View this thread: http://www.excelforum.com/showthread...hreadid=483069


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Password - 3 chances and **off


I have put this in as an example as i did not want to show my password.

Password = ""
If TextBox1 = Password Then

However we can assume that the code will read something like

Password = "Bob"
If TextBox1 = Password Then.

I chose unload me so that if the code was eneted incorrectly or the
cancel button is hit then the form does not load. Therefore the address
book can not be accessed.

Is there a bit of code for a three chances and then exit the form.


--
Shake
------------------------------------------------------------------------
Shake's Profile: http://www.excelforum.com/member.php...o&userid=28577
View this thread: http://www.excelforum.com/showthread...hreadid=483069

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Password - 3 chances and **off


Try below. However, if Excel is exited and re-opened, the user gets a
new lease of lease for another 3 attempts.


Public Sub PasswordOK_Click()
Dim Password As String
Dim count As Integer
STATIC CNT


CNT = CNT+1
IF CNT =3 THEN EXIT SUB

Password = "*SESAME*"
If TextBox1 = Password Then
Personal_Details.Show
Unload Me
End If

If TextBox1 < Password Then
TextBox1 = ""
Label1.Visible = True
PasswordOK.Visible = False
PasswordCancel.Visible = False
Application.Wait Now + TimeValue("00:00:02")
Label1.Visible = False
PasswordOK.Visible = True
PasswordCancel.Visible = True
End If
End Sub


--
davidm
------------------------------------------------------------------------
davidm's Profile: http://www.excelforum.com/member.php...o&userid=20645
View this thread: http://www.excelforum.com/showthread...hreadid=483069

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Password - 3 chances and **off


Try below. However, if Excel is exited and re-opened, the user gets
new lease of life for another 3 attempts.


Public Sub PasswordOK_Click()
Dim Password As String
Dim count As Integer
STATIC CN


CNT = CNT+1
IF CNT =3 THEN EXIT SU

Password = "*SESAME*"
If TextBox1 = Password Then
Personal_Details.Show
Unload Me
End If

If TextBox1 < Password Then
TextBox1 = ""
Label1.Visible = True
PasswordOK.Visible = False
PasswordCancel.Visible = False
Application.Wait Now + TimeValue("00:00:02")
Label1.Visible = False
PasswordOK.Visible = True
PasswordCancel.Visible = True
End If
End Su

--
david
-----------------------------------------------------------------------
davidm's Profile: http://www.excelforum.com/member.php...fo&userid=2064
View this thread: http://www.excelforum.com/showthread.php?threadid=48306



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Password - 3 chances and **off


David M.

That was an ingenious bit of coding. Thank you ver
much!!!!!!!!!!!!!!!!!!!

--
Shak
-----------------------------------------------------------------------
Shake's Profile: http://www.excelforum.com/member.php...fo&userid=2857
View this thread: http://www.excelforum.com/showthread.php?threadid=48306

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Password - 3 chances and **off


Shake,

My pleasure. I was just having another look at the code. There is
small howler (which you probably picked up).

If cnt *=*3 Then Exit sub should be If cnt* *3 Then Exit sub.


Davi

--
david
-----------------------------------------------------------------------
davidm's Profile: http://www.excelforum.com/member.php...fo&userid=2064
View this thread: http://www.excelforum.com/showthread.php?threadid=48306

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Highlighting chances in shared worksheets Dream Excel Worksheet Functions 1 June 14th 08 10:45 PM
Need help! Chances are it's a simple formula I'm overlooking [email protected] Excel Discussion (Misc queries) 6 April 19th 07 05:46 AM
Terrible Excel Ruined My Chances of Graduation David Excel Discussion (Misc queries) 1 March 30th 06 10:05 AM
how to automate opening a password protected excel file? e.g. a .xls that has a password set in the security tab. Daniel Excel Worksheet Functions 0 June 23rd 05 11:56 PM
bypass password when update linking of password protected file Yan Excel Discussion (Misc queries) 1 February 7th 05 11:29 PM


All times are GMT +1. The time now is 11:44 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"