Code

crcastilla

Registered User.
Local time
Today, 15:15
Joined
Aug 20, 2011
Messages
21
Hello,

I want to put a check box in a form and I want it so I want to check the box it asks me for a password.

How do I do this?

Thank you!
 
I meant to say so when I try to check the box it will ask me for the password.

Please help.
 
Use the on Dirty event of the control.
Code:
Private Sub txtPicklistDate_Dirty(Cancel As Integer)
    If InputBox("Enter Password Please") <> "somevalue" Then
        MsgBox "Password Invalid.", vbOKOnly
        Cancel = True
        Exit Sub
    End If
End Sub
 
Okay so this is what I typed

Private Sub Sales_Click()
If InputBox("Enter Password Please") <> "somevalue" Then
MsgBox "Password Invalid.", vbOKOnly
Cancel = True
Exit Sub
End If
End Sub


It does ask me for the password but it still lets me check the box. I want so when I want to check the box it will ask me for the password and if I put the wrong password the box will not get checked.

Sorry I did not explain that earlier.
 
You could use this

Code:
Private Sub Sales_Click()
If InputBox("Enter Password Please") <> "somevalue" Then
     MsgBox "Password Invalid.", vbOKOnly
     Me!sales=false
else
    Me!sales=true
End If
End Sub
 
I know this is old but I forgot that I also want it that whenever I try to uncheck the box it will ask me for the same password and I don't put it in correctly then it will not be unchecked.
 
I looked at this again and it appears that checkboxes don't have onDirty events. Cancel only works in an event that is cancellable. That means you need to use the control's BeforeUpdate event. Using the Click event won't work because you need to be able to cancel the update. The code doesn't check for check or uncheck so it doesn't matter what the previous value was. All the code does is to prompt for a password if the field is changed and prevent the change if the password is invalid. The undo backs out the change so the user won't keep getting prompted for the password. If you don't use the undo (I rarely do), the user will have to use the esc key to back out the change himself.
Code:
    If InputBox("Enter Password Please") <> "somevalue" Then
        MsgBox "Password Invalid.", vbOKOnly
        Me.Sales.Undo
        Cancel = True
        Exit Sub
    End If
 

Users who are viewing this thread

Back
Top Bottom