Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270

    Uhh...
    Try:
    Code:
    If Not IsEmpty(ctrl) And Not IsNull(ctrl) And Not ctrl Is Nothing Then

  2. #17
    Emma35 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Ireland
    Posts
    65
    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 ?

  3. #18
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    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?

  4. #19
    Emma35 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Ireland
    Posts
    65
    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
    Attached Files Attached Files

  5. #20
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    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:
    Code:
    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)
    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 else

    Edit2:
    Also you need to exclude from code option group on which you "select type" so change this:
    Code:
    If ctrl.ControlType = acOptionGroup Then
    to this:
    Code:
    If ctrl.ControlType = acOptionGroup And ctrl.Name<> "FrameSelect" Then

  6. #21
    Emma35 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Ireland
    Posts
    65
    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

  7. #22
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    Happy to help And 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:
    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
    and then in every option group After Update event call this procedure:
    Code:
    Private Sub FrameP1_AfterUpdate()
        CountGroups
    End Sub
    Much less code, much less possibilities to mess it up

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 04-15-2014, 01:59 PM
  2. Counting Checkboxes
    By maxx102 in forum Queries
    Replies: 2
    Last Post: 12-19-2012, 08:09 AM
  3. COUNT Group Count Records COUNT FUNCTION
    By PMCOFFEY in forum Access
    Replies: 9
    Last Post: 11-09-2012, 09:40 PM
  4. Checkboxes ?
    By Trojnfn in forum Access
    Replies: 3
    Last Post: 09-30-2011, 01:52 PM
  5. Reports and Checkboxes
    By seah0rse in forum Access
    Replies: 1
    Last Post: 06-07-2011, 03:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums