View Single Post
  #7  
Old May 20th, 2010, 03:36 PM posted to microsoft.public.access.forms
Jon Lewis[_3_]
external usenet poster
 
Posts: 40
Default looping through controls - for each ... next

Yes I think you do need another For Next loop if you are going to warn the
user *only* if any of the CheckBoxes are checked not least because your
logic at the moment leaves previously unchecked CheckBoxes disabled. Why
not warn them anyway something like "Any related checked boxes will be
unchecked ." I've assumed you want all related CheckBoxes to remain
Enabled. Try the following:

Dim ctl As Control

If Me.cboColor = "Yes" Then
For Each ctl In Me.Controls
If ctl.Tag = "Col" Then
ctl.Enabled = True
End If
Next
Else
For Each ctl In Me.Controls
If ctl.Tag = "Col" Then
If ctl.Value = True Then
If MsgBox("All related check boxes will be unchecked - is
this OK?", vbExclamation + vbYesNo) = vbNo Then
Me.cboColor = "Yes"
Exit Sub
End If
End If
End If
Next
For Each ctl In Me.Controls
If ctl.Tag = "Col" Then
ctl.Value = Null
ctl.Enabled = False
End If
Next
End If

Jon

"Kurt Heisler" wrote in message
...
If the user checks selects 'Yes' from a combo box, I'd like to enable
a group of check boxes (all have tag property "col"). If the user
selects 'No', I'd like to disable them but, if any are checked, tell
the user data will be deleted and then set the checkboxes = Null
(assuming the user says okay). My current code triggers the prompt for
*each* check box that's checked, rather then looping through them
automatically. Do I need to another "For each ..." clause after the
first Else statement?

###

Private Sub cboColor_AfterUpdate()

For Each ctl In Me
If ctl.Tag = "col" Then
If Me.cboColor.Value = "Yes" Then
ctl.Enabled = True
Else
If ctl.Value = False Then 'nothing has been checked;
disable the controls
ctl.Enabled = False
Else 'something has been checked; tell user it will be
deleted
iresponse = MsgBox("Changing this from Yes will delete
the information in the " & _
"related fields." & _
Chr(13) & Chr(13) & "Continue?", 4 + 48 + 256, "Delete
confirmation")
If iresponse = 7 Then ' user said
No
Me.cboColor.Value = "Yes"
Exit Sub
Else ' user said Yes
ctl.Value = Null
ctl.Enabled = False
End If
End If
End If
End If
Next
Set ctl = Nothing

End Sub

###

Thank you.