PDA

View Full Version : Solved: Checkbox confirmation



Dave_C
03-17-2008, 06:12 PM
Hi, I've been asked at work to take over the updating of an excel VBA form and while i have a fair bit of experience with excel i don't have any with VBA. I'm confident i'll pick it up quickly (or at least what i need quickly) but i need to get this first change done asap.

On a UserForm there is one checkbox. When this is clicked i would like to have another UserForm come up with a confirmation statement on it and Yes or No command buttons. Yes and the tick stays in the checkbox, No and the tick is removed.

Can someone point me in the right direction for the VBA code to put in / take out the tick please?

mikerickson
03-17-2008, 06:24 PM
You wouldn't need another Userform, a Message Box should serve.

Put this in the Userform's code module and it will inquire any time the checkbox is changed.
Private Sub CheckBox1_Click()
Me.CheckBox1.Value = (MsgBox("Do you want the check box checked?", vbYesNo) = vbYes)
End Sub


This will inquire when the box is checked, but will not inquire when un-checking the box.
Private Sub CheckBox1_Click()
With Me.CheckBox1
If .Value Then .Value = (MsgBox("Do you want the check box checked?", vbYesNo) = vbYes)
End With
End Sub

Dave_C
03-19-2008, 12:41 PM
Thanks Mike. Just what i was looking for. Once pointed in the right direction i found some more examples and customised the Message Box.
Had the meeting at work for it today and was told this change was exactly what they wanted.

Cheers Mike

mikerickson
03-19-2008, 04:52 PM
Glad to have helped.