Password on clicking button

Posted on 2014-08-19
Last Modified: 2014-08-20

I have a button where users can click it, it runs a sub and it clears some data onto a log, i want to run a password through that so that only certain users can clear the log,

how can i run a password through?

Question by:Seamus2626
    LVL 27

    Accepted Solution

    You can just add an input box to your code that prompts for and checks against a defined password:
        pword = Application.InputBox("Enter password to clear log", "PASSWORD REQUIRED")
        If pword = "PASSWORD" Then
            'statements that clear the log
        End If

    Open in new window

    LVL 2

    Assisted Solution

    by:Andrew Velasco

    You could make a userform with a textbox.  In the textbox properties, change the PasswordChar value to "*", making the password text not readable to others.  (Make sure to include a "Submit" and "Cancel" button.  Then when the user clicks the button have it call the userform, enter the password, hide the userform and reference the password text box:
    Public strPassword as String
         strPassword = MyUserForm.PasswordTextBox.Value
         If strPassword = "YourPassWord" Then
              Your Code
         End If
    End Sub

    Open in new window

    More on UserForms

    Author Closing Comment

    Thanks guys!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
    The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
    This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now