Excel Password problem

tigerdel

New member
Joined
Aug 23, 2012
Messages
40
Reaction score
0
Points
0
Location
Cambridgeshire
Excel Version(s)
Office 365
Hi

I have a button that opens a UserForm and requests a Password

If the user gets the Password right then this works fine.

If the user gets the Password then it asks if they would like to retry, if they say yes then the userform simply closes.

What have I done wrong in my code???

Code:
Private Sub CommandButton1_Click()[COLOR=#333333]
[/COLOR]If Me.TextBox1.Value = "secret" Then
Unload Me
ActiveWorkbook.Sheets("DCW").Visible = True
Sheets("DCW").Select
Range("A1:A2").Select
Else
Me.Hide
Retry = MsgBox("Incorrect Password" & vbNewLine & "Do you wish to try again?", vbYesNo, "Retry")
Select Case "Retry"
Case Is = vbYes
Me.TextBox1.Value = ""
Me.TextBox1.SetFocus
Me.Show
Case Is = vbNo
Unload Me
End Select
End If
End Sub

Thanks
 
Try this:

Code:
Private Sub CommandButton1_Click()
    
    If Me.TextBox1.Value = "secret" Then
        Unload Me
        ActiveWorkbook.Sheets("DCW").Visible = True
        Sheets("DCW").Select
        Range("A1:A2").Select
        bClear = True
    Else
        Select Case MsgBox("Incorrect Password" & vbNewLine & "Do you wish to try again?", vbYesNo, "Retry")
            Case Is = vbYes
                Me.TextBox1.Value = ""
                Me.TextBox1.SetFocus
            Case Is = vbNo
                Unload Me
                bClear = True
        End Select
    End If
End Sub
 
Back
Top