View Single Post
  #9  
Old May 21st, 2010, 02:45 AM posted to microsoft.public.access.forms
mie via AccessMonster.com
external usenet poster
 
Posts: 9
Default looping through controls - for each ... next

This code untested..


Private Function iCheck() As Boolean
Dim ctl As Control
iCheck = True

For Each ctl In Me.Controls
If ctl.Tag = "Col" Then
If ctl.Value = True Then
iCheck = False
Exit Function
End If
End If
Next
End Function

Private Sub iDisabled()
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "Col" Then ctl.Enabled = False
Next
End Sub

Private Sub iEnabled()
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "Col" Then ctl.Enabled = True
Next
End Sub

Private Sub chgFalse()
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "col" Then
If ctl.Value = True Then ctl.Value = False
End If
Next
End Sub

Private Sub cboColor_AfterUpdate()
Dim iResponse As Integer

If Me.cboColor = "Yes" Then
'--Enabled all check box
iEnabled
Else
If iCheck = False Then
iResponse = MsgBox("YourMessange", vbYesNo, "Title")

If iResponse = vbYes Then
'--change value to False
chgFalse
'--disable all check box
iDisabled
Else
Exit Sub
End If
Else
'--All check box = True
iDisabled
End If
End If
End Sub


Kurt Heisler wrote:
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

[quoted text clipped - 80 lines]

Thank you.


Jon:

Your code has the same problem mine has: It prompts the user for
*each* checkbox that's = True. (So if 3 checkboxes are checked, he
gets asked 3 times, "... is this OK?")

mie:

I can't follow how your code comes together. I ignored the first code
you posted, and you came back with this:

Dim ctl As control
For Each ctl In Me.Controls

[quoted text clipped - 7 lines]
End If
Next


So where / how do I incorporate the iresponse ... question for the
user? The above code will change all True checkboxes to False without
first asking the user.

Also:

For me, i will ask user confirmation once only. Then proceed the cancellation process. Imagine if you have 10 check boxes, user will be prompted 10 time for confirmation.


That's the problem I'm trying to fix. If I can have Access loop
through the controls automatically it should mean the user gets one
prompt and not, e.g., 10.


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/201005/1