PDA

View Full Version : Solved: enable more options in userform with password



stramvaier
06-28-2012, 01:28 AM
Hi.
I need help generating a code that by activating an optionbutton, promts a window and asks for a password. When correct password, additional optionbuttons will be visible/usable in the userform.

I am clueless to how to start this code and my main problem is how to code a popup of a passwordwindow.

Any help is apreciated.

lynnnow
06-28-2012, 01:32 AM
Will the optionbutton be on a userform or in the XL sheet?

Bob Phillips
06-28-2012, 01:42 AM
As it is a password, you should build another userform as textboxes on a form have a PasswordChar property that can mask the input.

stramvaier
06-28-2012, 05:25 AM
it is in an allready existing userform. the userform runs a code almost a mile long ;) and i want to add some options that only a few persons are going to be able to use. The userform has about 50 different options allready, and i want to add 3 optionbuttons that are hidden from veiw unless you unlock them with a password.

Bob Phillips
06-28-2012, 05:37 AM
AsI say, to get the password, create a new userform and launch that from within the existing userform.

IanFScott
06-28-2012, 06:07 AM
You need a button or label (either of which are clickable).
In the code behind the button:

Private Sub CommandButton1_Click()
Constr PWD As String = "letmein"
Dim Result As Variant
Result = InputBox("Enter Password:","")
If Len(Result) = 0 Then Exit Sub ' Cancel Pressed
If Result = RWD Then
UnhideControls True
Else
UnhideControls False
End If
End Sub
Sub UnhideControls(blHide as Boolean)
With Me
.optM1.Visible = blHide
.optM2.Visible - blHide
End With
End Sub


Obviously this needs adjusting to your form but the principle is fine.

Rob342
06-28-2012, 11:31 AM
As Xld said its better to have a user form pop up then you can mask the password.
If you are not in a desperate hurry, i have got an example you could use.

let me know and i will extract it out of the current form i'm using.

Rob

stramvaier
06-28-2012, 11:38 PM
Thanks IanFScott. :thumb
Your code did exactly as i wanted(after a little tweak). Problem solved.

:friends: