ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   userform command button checkbox problem (https://www.excelbanter.com/excel-programming/382380-userform-command-button-checkbox-problem.html)

[email protected]

userform command button checkbox problem
 
Hi

I am new to this list, but would appreciate any help available.

I have userrform with several clusters of checkboxes and for each
cluster a command button that allows the user to select or deselect
all the check boxes in a cluster, using code typically as follows:

Private Sub cmdSelAllStages_Click()

' select / deselect all stages, if any stage is false make them
all true,
' else make all stages false

If chkPPM0 = False Or chkPPM1 = False Or chkPPM2 = False Or
chkPPM3 = False Then
chkPPM0 = True
chkPPM1 = True
chkPPM2 = True
chkPPM3 = True
Else
chkPPM0 = False
chkPPM1 = False
chkPPM2 = False
chkPPM3 = False
End If

. . . . . . . .

End Sub

Each checkbox has a worksheet cell set as its 'controlsource' property
to store its current value.

Problem is that when the userform is displayed and one, some or all of
the cluster of checkboxes is false then, when the command button is
clicked as the first action, the code only makes the first checkbox in
the cluster true (or the first checkbox in the cluster that is false,
true) instead of, as I want, making all the checkboxes true if any of
them are false.

The reverse is also true - if all boxes are true when command button
is clicked it makes only the first box untrue, rather than making all
of them untrue.

The command buttons work fine on any subsequent occassion when the
command button is clicked - it is just when it is the first action on
using the userform that the problem occurs!

Can anyone explain this or provide a fix for it?

Any help much appreciated, its got me baffled.

Mike


Jim Cone

userform command button checkbox problem
 
Mike,
Checkboxes can have a Null value as well as True or False.
I suspect that you did not set the values for the boxes during
the design of the form.
However, try changing "= False" to "< True"
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



wrote in message
Hi
I am new to this list, but would appreciate any help available.

I have userrform with several clusters of checkboxes and for each
cluster a command button that allows the user to select or deselect
all the check boxes in a cluster, using code typically as follows:

Private Sub cmdSelAllStages_Click()

' select / deselect all stages, if any stage is false make them
all true,
' else make all stages false

If chkPPM0 = False Or chkPPM1 = False Or chkPPM2 = False Or
chkPPM3 = False Then
chkPPM0 = True
chkPPM1 = True
chkPPM2 = True
chkPPM3 = True
Else
chkPPM0 = False
chkPPM1 = False
chkPPM2 = False
chkPPM3 = False
End If

. . . . . . . .

End Sub

Each checkbox has a worksheet cell set as its 'controlsource' property
to store its current value.
Problem is that when the userform is displayed and one, some or all of
the cluster of checkboxes is false then, when the command button is
clicked as the first action, the code only makes the first checkbox in
the cluster true (or the first checkbox in the cluster that is false,
true) instead of, as I want, making all the checkboxes true if any of
them are false.
The reverse is also true - if all boxes are true when command button
is clicked it makes only the first box untrue, rather than making all
of them untrue.
The command buttons work fine on any subsequent occassion when the
command button is clicked - it is just when it is the first action on
using the userform that the problem occurs!
Can anyone explain this or provide a fix for it?
Any help much appreciated, its got me baffled.
Mike



All times are GMT +1. The time now is 08:44 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com