+ Reply to Thread
Results 1 to 8 of 8

How to have multiple passwords for a userform button

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    213

    How to have multiple passwords for a userform button

    Looking at the below site:

    1.

    http://www.mrexcel.com/forum/excel-q...nd-button.html

    Private Sub CommandButton1_Click()
        Dim pword As String
            pword = InputBox("Please enter the password", "Password Required")
            
            If pword <> "bigdog" Then
                MsgBox "Yo...You aren't allowed to do that!", vbCritical + vbOKOnly, "Get Outta here!"
                Exit Sub
            Else
                MsgBox "proceed"
                '   Your code here
            End If
    End Sub
    I want to know how can one have multiple password options for the button. For example, "bigdog" as well as "shoes" as well as "deskchair". I tried commas and Or but I get an error

    Also:

    2.

    Looking at the below code:
    Private Sub CommandButton1_Click()
    If TextBox1.Value = "yoyo3" Then
    Unload Me
    UserForm2.Show
    End If
    If TextBox1.Value <> "yoyo3" Then
    MsgBox "Sorry wrong password"
    TextBox1.Value = ""
    Exit Sub
    End If
    End Sub
    How can one have more than one password? For example, "yoyo3" as well as "curtainthread" as well as "mountaintree"

    Thanks!

  2. #2
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,028

    Re: How to have multiple passwords for a userform button

    something similar
     If TextBox1.Text = "34" Or "12" Then
     Sheet2.Visible = xlSheetVisible
     Else
     Sheet2.Visible = xlSheetVeryHidden
     End If
    Private Sub UserForm_Initialize()
            TextBox1.PasswordChar = "*"
    Regards, John55
    If you have issues with Code I've provided, I appreciate your feedback.
    In the event Code provided resolves your issue, please mark your Thread as SOLVED.
    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

    ...enjoy -funny parrots-

  3. #3
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    213

    Re: How to have multiple passwords for a userform button

    Thanks john55 but I tried it and got the below:

    Run-time error '13':

    Type mismatch

  4. #4
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,028

    Re: How to have multiple passwords for a userform button

    perhaps
    Select Case TextBox1.Value
    Case "aaa", "bbb", "ccc"
    UserForm2.Show
    Case Is <> "aaa", "bbb", "ccc"
    MsgBox "wrong!"
    End Select
    End Sub

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: How to have multiple passwords for a userform button

    Hi, chin67326,

    code in ThisWorkbook:
    Private Sub Workbook_Open()
    UserForm1.Show
    End Sub
    Code behind UserForm1:
    Private Sub cmdCancel_Click()
    MsgBox "This workbook needs registration, Workbook will be closed"
    ThisWorkbook.Close False
    End Sub
    
    Private Sub cmdOK_Click()
    Select Case txtPassword.Text
      Case "yoyo3", "curtainthread", "mountaintree"
        Me.Hide
        UserForm2.Show
        Unload Me
      Case Else
        MsgBox "no admittance"
        ThisWorkbook.Close False
    End Select
    End Sub
    Ciao,
    Holger
    Attached Files Attached Files
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  6. #6
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    213

    Re: How to have multiple passwords for a userform button

    This worked john55; THANKS!

  7. #7
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,028

    Re: How to have multiple passwords for a userform button

    glad to be of help!

  8. #8
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    213

    Re: How to have multiple passwords for a userform button

    Thanks Holger!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Password for custom userform login only works with text passwords
    By Nitefox in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-23-2014, 06:45 PM
  2. [SOLVED] VBA for Option Button on Userform to send data to Multiple Spreadsheets
    By rcfrench in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-08-2013, 11:43 AM
  3. Excel Userform - Button to search multiple columns
    By Nu2Java in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-09-2012, 09:54 PM
  4. Userform cancel button - how to exit multiple subs
    By sotiris5000 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-16-2010, 09:56 AM
  5. multiple passwords
    By vivi in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 04-08-2010, 11:10 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1