userform command button checkbox problem

M

ma.cantwell

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
 
J

Jim Cone

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


<[email protected]>
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top