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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

chk buttons how to do this

Status
Not open for further replies.

johnnyv

Programmer
Jul 13, 2001
216
CA
Hello all

here is my situation

I have a total of 7 check buttons on a form. The first 6 are grouped together in an array. The user can select any or all of these buttons. The 7'th button is selected when the user wants none of the above. Here is my problem. When the user enters the form and selects none of the above each of the first 6 buttons has a value of unchecked and the 7'th button a value of vbchecked. But, when the user first selects 1 or more the first 6 then changes their mind and selects none of the above I can not get the value of the 7'th to be vbchecked. The problem lies in tha fact that when the user selects none of the above I set the value of each of the first 6 to vbchecked. This calls the click event of the first 6 to be executed. In there I have a line that sets the none above value to unchecked.

Any thoughts here is my code, so for the lon winded explanation.

'code for none of the above
Private Sub chkNoneAbove_Click()
Dim icounter As Integer
'clear buttons if none of the a bove is choosen
For icounter = 0 To 5
chkQ5(icounter).Value = Unchecked
Next icounter
end sub

'code for 6 buttons
Private Sub chkQ5_Click(Index As Integer)

chkNoneAbove.Value = Unchecked

End Sub
 
On your click event - check the value of each of the First
Boxes.
If any one is Checked then uncheck the 7th box.

eg:

dim I as integer
dim isChecked as boolean

for I = 0 to 5
if chekQ5(I).value = vbChecked then isChecked=true
next

if ischecked then
chkNoneAbove.Value = Unchecked
else
chkNoneAbove.Value = Checked
end if


Hope this helps
 
The problem lies in tha fact that when the user selects none of the above I set the value of each of the first 6 to vbchecked. This calls the click event of the first 6 to be executed.

The standard way of dealing with this kind of problem is to declare a form level boolean variable (say mblnClearingFromCode) and use it soemthing like this.

Code:
private mblnClearingFromCode as boolean

Private Sub chkNoneAbove_Click()
  Dim icounter As Integer
  'clear buttons if none of the above is choosen
[COLOR=red]  'Now set flag so we know we are clearing the box

mblnClearingFromCode = true
[/color]

      For icounter = 0 To 5
        chkQ5(icounter).Value = Unchecked
      Next icounter
[COLOR=red]'done clearing so now reset our flag
mblnClearingFromCode = false
[/color]

end sub

'code for  6 buttons
Private Sub chkQ5_Click(Index As Integer)

[COLOR=red]    if mblnClearingFromCode = false then [/color]
      chkNoneAbove.Value = Unchecked
[COLOR=red]    end if [/color]
 
End Sub

Hope that helps



Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top