Results 1 to 10 of 10
  1. #1
    excellenthelp is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    93

    VBA to uncheck ALL checkboxes in a subform

    Hello,



    What is the correct code to uncheck ALL checkboxes in a subform when an user clicks on "cancel" button on a main form?

    Here is the code I have tried to use - to no success:
    Code:
    Private Sub btnReturn_Click()
       Dim ctl As Control
       For Each ctl In Me!frmSupport_CARptUpdate_Subform.Form
            If ctl.ControlType = acCheckBox Then
                ctl = False
            End If
        Next
        DoCmd.Close
    End Sub
    I suspect it is the reference error. Debug leads me to the red highlighted area.

    Thanks!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,972
    What do you mean by 'all' checkboxes - there are multiple checkbox controls as seen in Design view OR there is one control that is repeated for multiple records as seen in Form view?

    Is frmSupport_CARptUpdate_Subform the name of subform container control? I always name container different from the object it holds, like: ctrDetails.

    For Each ctl In Me.ctrDetails.Form
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    excellenthelp is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    93
    There is one checkbox in the subform's design view.

    In the form view, there is a field with the checkboxes. Some are checked and some are not.

    As you said, there is one control that is repeated for multiple records as seen in Form view.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,972
    I forgot to ask what 'no success' means - error message, wrong results, nothing happens? What is exact error message?

    If checkbox is bound to field then your code would do no more than change the value of current record. You need to UPDATE all relevent records.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    excellenthelp is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    93
    No success = No change, except to first record on top of the datasheet (subform in main form in Form view)

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,972
    Possibly I edited my post as you were posting. Might read it again.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    excellenthelp is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    93
    Update? How do I update a subform?

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,972
    Options:

    1. run an UPDATE sql action on the table, something like
    CurrentDb.Execute "UPDATE tablename SET fieldname=False WHERE ID=" & Me.ID

    2. cycle through records of subform - this is more complicated
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    excellenthelp is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    93
    Okay thanks. I will update this thread with a solution when I find one.

    Thanks, June7!

  10. #10
    excellenthelp is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    93
    HeH! It was an easy code! Duh me.

    Code:
    Private Sub btnReturn_Click()   Dim strSQL As String
            strSQL = "Update qryAIA_CARptUpdate Set [CARptUpdate] = False"
            CurrentDb.Execute strSQL
    
    
        DoCmd.Close
    End Sub
    Marking this as SOLVED.

    Again, thank you, June7!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Uncheck Radio Button?
    By taimysho0 in forum Programming
    Replies: 2
    Last Post: 06-29-2012, 03:44 PM
  2. Replies: 8
    Last Post: 05-25-2012, 11:42 AM
  3. Right Click checkbox to uncheck?
    By JubilantJeff in forum Forms
    Replies: 7
    Last Post: 12-19-2011, 02:12 PM
  4. Checkboxes ?
    By Trojnfn in forum Access
    Replies: 3
    Last Post: 09-30-2011, 01:52 PM
  5. Check/Uncheck Checkbox on "Enter" click
    By emilyrogers in forum Forms
    Replies: 2
    Last Post: 02-17-2011, 10:24 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