PDA

View Full Version : Solved: CheckBox Help



TBS2766
03-17-2011, 11:13 AM
I am new to VBA and am trying to write a code that when someone clicks on the checkbox it prompts for a password. If password is false I want the checkbox to remain unchecked and a msgbox to appear saying not authorized. If password is true then the checkbox would be checked and a macro would run. I have experimented with the code and have managed to do everything expect have to checkbox remain unchecked if incorrect password is given. Can someone help me with just this step?:help

This is the half of the code I have come up with through trial and error for an incorrect password:
Sub CheckBox1_Click()
Dim myPWD As String
Dim userPWD As String
myPWD = "123"
userPWD = InputBox(Prompt:="Password")
If userPWD <> myPWD Then
MsgBox "Not Authorized"
Exit Sub
End If
End Sub

Rob342
03-17-2011, 12:37 PM
Hi TBS

Try this


Private Sub CheckBox1_Click()
Dim Password As String
Dim Inpass As String
Const PWD As String = "Password"
If CheckBox1 = True Then
End If
Inpass = Application.InputBox("Please Enter The Password To Proceed. Enter To Cancel.")
If Inpass = "" Or Inpass <> PWD Then
CheckBox1 = False
Else
CheckBox1 = True
End If

End Sub


Rob

TBS2766
03-17-2011, 12:51 PM
Rob342

Tried what you suggested but no matter what i enter in the password prompt box then outcome is the same the checkbox remains checked.

Any other suggestions???

Rob342
03-17-2011, 12:57 PM
Hi TBS
1st of all you posted this to the wrong forum, should be Excel forum you'll have MD after you.

posted my copy of the workbook, works ok in that one, please look at the properties box on the chkbox. I have set the cell value.

Rob

TBS2766
03-18-2011, 05:41 AM
Thank you Rob that worked by setting the cell value.
I apologize that this ended up in the wrong forum. I was looking in the excel forum when I entered my post so have no idea.

Thanks again:clap2:

Rob342
03-18-2011, 09:51 AM
Hi TBS

Glad it worked ok, you have set the cell value with chkboxes, worth remembering.

Glad to be of some assistance

Rob

Ps can you mark as solved ok