Results 1 to 4 of 4

Thread: Excel Password problem

  1. #1
    Acolyte tigerdel's Avatar
    Join Date
    Aug 2012
    Location
    Cambridgeshire
    Posts
    29
    Articles
    0
    Excel Version
    Office 365

    Excel Password problem



    Register for a FREE account, and/
    or Log in to avoid these ads!

    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()
    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

  2. #2
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,284
    Articles
    57
    Blog Entries
    14
    Excel Version
    Excel Office 365 Insider
    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
    Ken Puls, FCPA, FCMA, MS MVP

    Learn to Master Your Data at the Power Query Academy (the world's most comprehensive online Power Query training), with my book M is for Data Monkey, or our new Power Query Recipe cards!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

  3. #3
    Acolyte tigerdel's Avatar
    Join Date
    Aug 2012
    Location
    Cambridgeshire
    Posts
    29
    Articles
    0
    Excel Version
    Office 365

    [SOLVED] Excel Password Problem

    Thank you works perfectly now

  4. #4
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,284
    Articles
    57
    Blog Entries
    14
    Excel Version
    Excel Office 365 Insider
    Cool deal!
    Ken Puls, FCPA, FCMA, MS MVP

    Learn to Master Your Data at the Power Query Academy (the world's most comprehensive online Power Query training), with my book M is for Data Monkey, or our new Power Query Recipe cards!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •