Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Uncheck yes/no if previous checkboxes TRUE

Status
Not open for further replies.

jh3016

Programmer
Jun 6, 2003
148
US
I have 5 checkboxes. If "None" is checked, then uncheck any of the previous checkboxes.

User and choose more than one box, but if None is check, then uncheck everything else.
Red
Yellow
Green
Blue
Brown
None

If user checks None, I want to uncheck Red, Yellow, Green, Blue and Brown. In other words, if None is checked, there should be no other boxes checked.

Thanks in advance.
 
In the form's Code Module, paste the following code:

Private Sub None_Click()
Me.Red = False
Me.Yellow = False
Me.Green = False
Me.Blue = False
Me.Brown = False
End Sub

Private Function Other_Click()
Me.None = False
End Function


Then set the OnClick Property for the Red, Yellow, Green, Blue and Brown Check Boxes to:
=Other_Click()


See if this does what you want.
 
Hoe are ya jh3016 . . . . .

In the [blue]After Update Event[/blue] for your [blue]None[/blue] checkbox, add the following code (replace with actual names of the controls):
Code:
[blue]   With Me
      If .cbNone Then
         .cbRed = False
         .cbYellow = False
         .cbGreen = False
         .cbBlue = False
         .cbBrown = False
      End If
   End With[/blue]


cal.gif
See Ya! . . . . . .
 
To TheAceMan1 -

This worked perfectly. However, I would now like to give an error message if None is checked and then the user tries to click any of the other boxes.

In other words, right now, if I click None, all of the boxes are unchecked. However, if I click None and then click Red, None and Red are both checked.

Thanks in advance.
 
If you use ByteMyzer's code then clicking any other box will uncheck the "None" box. You could also
[blue][tt]
Private Sub Red_Click()
If None.Value AND Red.Value Then
MsgBox "'None' is Checked"
Red.Value = FALSE
End IF
End Sub
[/tt][/blue]
 
OK jh3016 . . . . .

[blue]Golom[/blue] and [blue]ByteMyzer[/blue] suggestions are right on! I'm just adding to your options with the following . . . . .

First remove the code from the [blue]After Update Event[/blue] for the None checkbox.

Next add the following code to the form module ( don't forget to replace all the [purple]purple[/purple] with the actual names of the boxes:
Code:
[blue]Public Sub cbHandler(ctlName As String)
   Dim Msg As String, Style As Integer, Title As String
   
   If ctlName = "[purple]cbNoneName[/purple]" Then
      If Me(ctlName) Then
         With Me
            ![purple]cbRedName[/purple] = False
            ![purple]cbYellowName[/purple] = False
            ![purple]cbGreenName[/purple] = False
            ![purple]cbBlueName[/purple] = False
            ![purple]cbBrownName[/purple] = False
         End With
      End If
   ElseIf Me(ctlName) Then
      If Me![purple]cbNoneName[/purple] Then
         Msg = "Your Message Here!"
         Style = vbInformation + vbOKOnly
         Title = "Your TitleBar Text Here!"
         Call MsgBox(Msg, Style, Title)
         Me(ctlName) = False
      End If
   End If
   
End Sub[/blue]
Next, add the following code to the [blue]After Update Event[/blue] for the checkboxes including the None:
Code:
[blue]   call cbHandler("[purple]Current cb Name Here![/purple]")[/blue]

cal.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top