If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
looping through controls - for each ... next
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. |
#2
|
|||
|
|||
looping through controls - for each ... next
Why not just show a warning message and get the response, then only run the
code if the user has agreed that the data can be changed. HTH, Rob Kurt Heisler wrote: 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. |
#3
|
|||
|
|||
looping through controls - for each ... next
If i understand correctly, what you want to do is, if user select 'YES', edit
data then suddenly change to 'NO'. So, all changes should be cancel, right? This code untested..i just copy n paste your code and add a few line. Dim ctl As Control 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 '--Add this Line. If ctl.Value = True Then ctl.Value = 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 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 '-----Put this line If ctl.Value=True Then ctl.Value = 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 Kurt Heisler wrote: 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. -- Message posted via http://www.accessmonster.com |
#4
|
|||
|
|||
looping through controls - for each ... next
Sorry, i didnt go through your code to the end. So, DONT USE THE CODE I
SUGGESTED. I''ll be back when i'am finished. mie wrote: If i understand correctly, what you want to do is, if user select 'YES', edit data then suddenly change to 'NO'. So, all changes should be cancel, right? This code untested..i just copy n paste your code and add a few line. Dim ctl As Control 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 '--Add this Line. If ctl.Value = True Then ctl.Value = 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 Private Sub cboColor_AfterUpdate() [quoted text clipped - 6 lines] disable the controls ctl.Enabled = False '-----Put this line If ctl.Value=True Then ctl.Value = False Else 'something has been checked; tell user it will be deleted [quoted text clipped - 18 lines] End Sub 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 [quoted text clipped - 43 lines] Thank you. -- Message posted via http://www.accessmonster.com |
#5
|
|||
|
|||
looping through controls - for each ... next
So here it is..(untested)
Dim ctl As control For Each ctl In Me.Controls If ctl.Tag = "Col" Then If Me.cboColor = "Yes" Then ctl.enabled = True Else If ctl.value = True Then ctl.value = False ctl.enabled = False End If End If Next 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.. Kurt Heisler wrote: 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. -- Message posted via http://www.accessmonster.com |
#6
|
|||
|
|||
looping through controls - for each ... next
If iresponse = 7 Then ' user said
No Me.cboColor.Value = "Yes" Exit Sub '---When user select "Yes", your procedure will stop at this point. Kurt Heisler wrote: 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. -- Message posted via http://www.accessmonster.com |
#7
|
|||
|
|||
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. |
#8
|
|||
|
|||
looping through controls - for each ... next
On May 20, 10:36*am, "Jon Lewis"
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 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. 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 If ctl.Tag = "Col" Then If Me.cboColor = "Yes" Then ctl.enabled = True Else If ctl.value = True Then ctl.value = False ctl.enabled = False End If 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. |
#9
|
|||
|
|||
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 |
#10
|
|||
|
|||
looping through controls - for each ... next
If only i can delete my previous post.. hmm never mind.
The code below are TESTED and working like i (or may be you) wanted it to.. 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 Private Function iCheck() As Boolean Dim ctl As Control iCheck = True For Each ctl In Me.Controls If ctl.ControlType = acCheckBox Then If ctl.Tag = "Col" Then If ctl.Value = True Then iCheck = False Exit Function End If End If End If Next End Function Private Sub iDisabled() Dim ctl As Control For Each ctl In Me.Controls If ctl.ControlType = acCheckBox Then If ctl.ControlType = acCheckBox Then If ctl.Tag = "Col" Then ctl.Enabled = False End If End If Next End Sub Private Sub iEnabled() Dim ctl As Control For Each ctl In Me.Controls If ctl.ControlType = acCheckBox Then If ctl.Tag = "Col" Then ctl.Enabled = True End If End If Next End Sub Private Sub chgFalse() Dim ctl As Control For Each ctl In Me.Controls If ctl.ControlType = acCheckBox Then If ctl.Tag = "col" Then If ctl.Value = True Then ctl.Value = False End If End If Next End Sub mie wrote: 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 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 - 30 lines] 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 |
|
Thread Tools | |
Display Modes | |
|
|