De: Ray Costanzo Objet: Re: Ending a do until loop after 3 tries Date : lundi 25 septembre 2000 06:54 Hi Maria, Here's one way to do it. Copy this into a module and watch what happens. (Purposely enter an incorrect password three times!) ******************************************* Option Explicit Dim intTries As Integer Sub InitializeIt() intTries = 0 Call GetPassword End Sub Sub GetPassword() If intTries = 3 Then MsgBox "Number of attempts exceeded!", vbCritical Exit Sub End If Select Case InputBox("Enter password:", "Password") Case "4q35kjq34k5jaksdjfa90su" MsgBox "Hey, thanks" Case Else intTries = intTries + 1 If intTries < 3 Then MsgBox "Incorrect password" Call GetPassword End Select End Sub *************************************** Ray Costanzo http://www.excelfiles.com mailto:ray@excelfiles.com On Sun, 24 Sep 2000 23:08:48 -0400, maria shared: >Hi: > >I am using the following code to prompt the user to enter a password to >be able to open an Excel workbook. > > >If Worksheets("ABC").Range("A1") = "Program expired" Then >Do Until Code = Worksheets("XYZ").Range("Code_Reqd") >Code = InputBox("Please enter code to re-activate program ! Program >Expired !") >Worksheets("xyz").Range("Enter_Code") = Code >If Code <> Worksheets("XYZ").Range("Code_Reqd") Then MsgBox "Please >re-enter correct code", vbOKOnly, "Invalid Code !" >If Code = Worksheets("XYZ").Range("Code_Reqd") Then MsgBox "Program >valid until -- " & Worksheets("XYZ").Range("Valid_Until"), vbOKOnly, >"Program re-activated !" >Loop >End If > > >I needed help with additional code so that if the user fails to enter >the correct password after 3 tries, a messagebox displays" >"Incorrect password, 3 attempts! The program will now close" >After this I want the workbook to close. > >As always, would appreciate your help. > >TIA > >Maria