Uhh...
Try:
Code:If Not IsEmpty(ctrl) And Not IsNull(ctrl) And Not ctrl Is Nothing Then
Uhh...
Try:
Code:If Not IsEmpty(ctrl) And Not IsNull(ctrl) And Not ctrl Is Nothing Then
Tried it and it's giving the same error. I was thinking, what if i changed them all to unbound and passed the value to a textbox (which is bound to a field)....would that make things easier ?
I'm not quite certain about what you mean by that so I restrain from advising it.
Could you upload your db or at lest screenshot of form on which you run this code?
Sorry i was probably talking s***e anyway. I've attached the database. I think part of the problem might be that my option buttons aren't returning True or False but rather a choice between A & B
Ok, I'm having trouble with this as well. Seems like individual checkboxes in option group don't return any value regardless if the're checked or not. Option group itself returns value of selected checkbox but checkbox doesn't and checking its value always results in error 2427.
What is it you wanted to achieve by counting those ticked checkboxes? Checking if all questions have been answered? Maybe there's other way, i.e. counting option groups with value different than zero/null?
BTW I suggest setting default value of all option groups to 0 so they look better on freshly open form.
Edit:
I re-read your OP and saw that you "...need a textbox at the end of the form which will count the amount of checkboxes which are checked (regardless of whether true or false)...". But, because checkboxes can be checked or unchecked (or no value, but let's forget that) and can't be "checked true or false" and also only one checkbox in option group can be checked at any time, my guess is you meant "count the amount of option groups that have at least one checkbox checked", is that right?
If so, then code will be:
But problem is it don't fire on Form On Current event and I don't know really on which one it will. It works ok if put in some button Click event or if called from every option group After Update event but someone more experienced needs to tell us, where elseCode:Dim iCounter As Integer Dim ctrl As Control iCounter = 0 For Each ctrl In Form.Controls If ctrl.ControlType = acOptionGroup Then If ctrl.Value <> 0 Then iCounter = iCounter + 1 End If End If Next ctrl Me.txtCount.SetFocus Me.txtCount.Value = Str(iCounter)
Edit2:
Also you need to exclude from code option group on which you "select type" so change this:
to this:Code:If ctrl.ControlType = acOptionGroup Then
Code:If ctrl.ControlType = acOptionGroup And ctrl.Name<> "FrameSelect" Then
Ah yes that's it working now
You're a genius man well done !. I added your code to each of the Option Groups and it works fine. The reason I needed to count them was that each time someone ticks a box it's deemed to be an 'action' in our world, and we had to total them. I also set the default value to zero on each group also and it looks much better on the Form. Oh, and well done for seeing that I didn't need to count the first group (that would have been my next question !)
Thank you again for your time and patience with this.....I appreciate it very much
Emma xx
Happy to helpAnd I learned something new on the way as well, so win-win.
One thing though - you don't need the same code on every option group After Update. Simply create one procedure like:
and then in every option group After Update event call this procedure:Code:Private Sub CountGroups() Dim iCounter As Integer Dim ctrl As Control iCounter = 0 For Each ctrl In Form.Controls If ctrl.ControlType = acOptionGroup Then If ctrl.Value <> 0 Then iCounter = iCounter + 1 End If End If Next ctrl Me.txtCount.SetFocus Me.txtCount.Value = Str(iCounter) End Sub
Much less code, much less possibilities to mess it upCode:Private Sub FrameP1_AfterUpdate() CountGroups End Sub![]()