Consulting

Results 1 to 14 of 14

Thread: Solved: Password entry visible

  1. #1
    VBAX Tutor
    Joined
    Jul 2009
    Posts
    207
    Location

    Solved: Password entry visible

    Hello
    I am trying to use this code to make access to other events password protected.It works ok except when you type 'MyPassword' it is visible in the entry box. Is there any code I can add to make it '**********'.

    [vba]
    Option Explicit

    'This code goes in UserForm OptionButton1, change the name to match your command buttons name.

    Private Sub OptionButton1_Click()
    Dim sPassword As String

    sPassword = InputBox("Enter Your Password")
    If sPassword = "mypassword" Then


    Else
    MsgBox "Password incorrect!"
    Exit Sub
    End If
    End Sub
    [/vba]

    Many thanks for any suggestions
    Gil

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You need to create a form, with a password textbox, and the PasswordChar property set to *
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Tutor
    Joined
    Jul 2009
    Posts
    207
    Location
    Hello xld
    Thanks for that info. I have created the form with a password textbox, set the PasswordChar to *.
    Then I inserted the above code and when entering the password the original box appears, so I deleted the line
    [vba] sPassword = InputBox("Enter Your Password")[/vba] Now as soon as any character is entered in the password box it goes straight to Password incorrect.
    So I tried inserting variations of
    [vba]
    sPassword = TextBox1("Enter Your Password")
    [/vba] but with no good result.
    Any further help will be appreciated
    Gil

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You need to show the form, and then check the password from within the form code. The option button code needs to know the result.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Tutor
    Joined
    Jul 2009
    Posts
    207
    Location
    Hello xld
    Sorry, I am lost on that one.
    Gil

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Show us all of the code Gil, we will just be talking cross-purposes otherwise.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    VBAX Tutor
    Joined
    Jul 2009
    Posts
    207
    Location
    Hello xld
    Please see the attachment for what I have so far.
    Gil

  8. #8
    VBAX Tutor lynnnow's Avatar
    Joined
    Jan 2005
    Location
    Mumbai, Maharashtra, India
    Posts
    299
    Location
    try this in your code:

    [VBA]Private Sub ok_Click()
    Dim sPassword As String
    If TextBox1.Value = "mypassword" Then
    Youhavebeensucessfull.Show

    Else
    MsgBox "Password incorrect!"
    Exit Sub
    End If
    End Sub[/VBA]

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Gil
    Hello xld
    Please see the attachment for what I have so far.
    Gil
    I don't get the error that you describe, it waits until I hit OK before it validates it.

    But you do have to test the correct thing

    [vba]

    Private Sub ok_Click()
    If TextBox1.Text = "mypassword" Then
    Youhavebeensucessfull.Show

    Else
    MsgBox "Password incorrect!"
    Exit Sub
    End If
    End Sub
    [/vba]

    and add some code for the cancel buttons.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  10. #10
    VBAX Tutor
    Joined
    Jul 2009
    Posts
    207
    Location
    Hello lynnnow
    Thank you for your reply and forgive me but don't I already have that code in my attachment. If it should be inserted elsewhere please advise
    Gil

  11. #11
    VBAX Tutor lynnnow's Avatar
    Joined
    Jan 2005
    Location
    Mumbai, Maharashtra, India
    Posts
    299
    Location
    Gil,

    Your code in the file is:

    [vba]Private Sub ok_Click()
    Dim sPassword As String
    If sPassword = "mypassword" Then '<<< Changed this line
    Youhavebeensucessfull.Show

    Else
    MsgBox "Password incorrect!"
    Exit Sub
    End If
    End Sub[/vba]
    I've corrected it to:

    [vba]Private Sub ok_Click()
    If TextBox1.Text = "mypassword" Then '<<< To this
    Youhavebeensucessfull.Show

    Else
    MsgBox "Password incorrect!"
    Exit Sub
    End If
    End Sub[/vba]
    You did not validate the value inserted in the textbox, that was the flaw in the code. As xld has pointed out, you need to add code for the Cancel button too.

    HTH

    Lincoln

  12. #12
    VBAX Tutor
    Joined
    Jul 2009
    Posts
    207
    Location
    Hello
    First of all may I say a big thank you to xld & lynnnow for being patient with me in my quest for the answer and for supplying the feeedback to resolve my issue.
    It all works for me just fine and have attached the workbook with the updated code with an odd bit or 2 added by me, so if there are any others like me out there struggling for a similar answer then I hope it helps them as much as me.
    All too often reading the posts they start with a problem for which suggestions are made and then closed as solved without an example of the solution being published for novices like me to study.
    Getting back to the code one more answer if possible is if you Cancel from the Password Entry screen I notice that the Option Button1 stays selected and is inoperable.
    Gil
    Last edited by Gil; 05-01-2010 at 11:16 AM.

  13. #13
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    That is a problem with using just a single option button, they are designed to be used in groups, to allow a single choice. When there is only one, it is better to use a button or a checkbox.
    Last edited by Bob Phillips; 05-01-2010 at 12:49 PM.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  14. #14
    VBAX Tutor
    Joined
    Jul 2009
    Posts
    207
    Location
    Thank you xld
    I have tried the other options of different buttons. In the end I decided to add a similar button just to make the change.
    But, the question always has to be asked just in case there is a neater solution.
    Many thanks again and I will mark this solved.
    Gil

Posting Permissions

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