PDA

View Full Version : Clear All Command Button in User Form



LLL
03-30-2009, 12:33 PM
Hello,

I have user forms I have created with checkboxes. As the items are checked off, I have it set to save the information. But what would be the code to have the checkboxes uncheck if you choose to clear all. BUT only clear when the button is clicked. Thanks

Here is an example of code for the checkboxes

Private Sub UserForm_Initialize()
Application.EnableEvents = False
Set r = ActiveCell
For i = 1 To 1
If r.Offset(, 88 + i) <> "" Then
Me.Controls("Checkbox" & i) = True
End If
Next
Application.EnableEvents = True
End Sub


'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Private Sub CheckBox1_AfterUpdate()
AddX Me.CheckBox1, r.Row, 103
End Sub

Bob Phillips
03-30-2009, 01:51 PM
Dim ctl As msforms.Control

For Each ctl In Me.Controls

If TypeName(ctl) = "CheckBox" Then

ctl.Value = False
End If
Next ctl

LLL
03-30-2009, 02:03 PM
This does work for clearing the form check boxes, but upon return to that cell containing the userform, when opened the checkboxes are again checked.

I have set this code to save the userform information, so maybe it is part of this code example. I need to save the checked boxes until I determine to Clear All checks.

Private Sub CheckBox1_AfterUpdate()
AddX Me.CheckBox1, r.Row, 103
End Sub

Thoughts?

Bob Phillips
03-30-2009, 03:47 PM
Cell containing the userform, what are you talking about? cells don't contain forms.

That code doesn't save userform information, it creates a checkbox.

It seems to me that maybe you don't have a userform.

LLL
03-30-2009, 04:01 PM
Here is an example of the one of the codes to initialize the form and provide for the checkboxes.



Private Sub UserForm_Initialize()
Application.EnableEvents = False
Set r = ActiveCell
For i = 1 To 1
If r.Offset(, 88 + i) <> "" Then
Me.Controls("Checkbox" & i) = True
End If
Next
Application.EnableEvents = True
End Sub
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Private Sub CheckBox1_AfterUpdate()
AddX Me.CheckBox1, r.Row, 103
End Sub


If I use the previous code provided

Dim ctl As msforms.Control

For Each ctl In Me.Controls

If TypeName(ctl) = "CheckBox" Then

ctl.Value = False
End If
Next ctl

It does clear the checkboxes. But upon return to the cell that initated the userform the form appears with boxes still checked