Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    khughes46 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Grapevine, TX
    Posts
    231

    Select all check boxes on a form (only one check box field is on the form)

    Is there a way to select all check boxes on a form; there is only one check box field on the form. If the solution is using VB then I am going to need step by step instructions on how to do it.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    Yes, requires VBA. More than one way to code.

    What is purpose of this action?

    What do you mean by 'all check boxes' - every record?
    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
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    yes there is

    Code:
    dim ctl as control
    
    for each ctl in me.controls
        if ctl.controltype = 106 'check box
            ctl.value = -1
        else
    
        endif
    next ctl
    you could attach this to any event on your form (i.e. ON CLICK of a button, etc)

  4. #4
    khughes46 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Grapevine, TX
    Posts
    231
    Yes. I have preselected a group of records for display. Once these are up I want to give the option to select some (checking each box) or all check one button to perform the select all action.

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    rpeare's example code is to set value of multiple checkboxes in a single record. If you want to set value of a single checkbox in multiple records, that requires code to cycle through the records or run an UPDATE sql to set value of specific records based on the form filter criteria.
    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.

  6. #6
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Excellent point, I had thought this was something like an automated report queue where it would print whatever reports were selected (whatever was checked off). This changes significantly if you are doing this on a bound form, somewhat easier on an unbound form.

  7. #7
    khughes46 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Grapevine, TX
    Posts
    231
    Tried this. I have a command buton, the ON CLICK entry is [Event Procedure]. The event has the following code:
    Private Sub Command23_Click()
    Dim ctl As Control
    For Each ctl In Me.Controls
    if ctl.controltype = 106 'check box
    ctl.Value = -1
    Else
    End If
    Next ctl
    End Sub

    I clicked the button and got the following:
    Compile Error
    Syntax Error

    Highlighted in yellow is Private Sub Command23_Click()
    Selected in blue is if ctl.controltype = 106 'check box

    What did I miss?

  8. #8
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    What references are you using?

    The ones I used to test the code are:

    Visual Basic for Applications
    Microsoft Access 12.0 Object Library
    OLE Automation
    Microsoft Office 12.0 Access database engine object library

    I believe it's one of the two object libraries that contain the reference you need.

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    Did you read post 5? Unless I completely misunderstand the requirements, I don't think rpeare's code is what you need.
    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.

  10. #10
    khughes46 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Grapevine, TX
    Posts
    231
    And where would I find these object libraries?

  11. #11
    khughes46 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Grapevine, TX
    Posts
    231
    I did just now. I've attached a copy of the form I am talking about. It's the profiles boxes I want to select all at once.

  12. #12
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by June7 View Post

    ...If you want to set value of a single checkbox in multiple records, that requires code to cycle through the records...
    Something like this:
    Code:
    Private Sub cmdTickAllBoxes_Click()
    
    Dim rs As DAO.Recordset
    
    Dim db As Database
    
    Set db = CurrentDb
    
    Set rs = db.OpenRecordset("ActualTableName")
    
    Do While Not rs.EOF
      rs.Edit
      rs!CheckboxField = -1
      rs.Update
      rs.MoveNext
    Loop
    
    rs.Close
    
    Set rs = Nothing
    
    Me.Requery
    
    End Sub

    Or if you want a single button to alternate between ticking all or unticking all:

    • Create a Command Button
    • Name it cmdTickUntickAllBoxes
    • Set it’s Caption to Tick All

    Now use this code:

    Code:
    Private Sub cmdTickUntickAllBoxes_Click()
    
    Dim rs As DAO.Recordset
    
    Dim db As Database
    
    Set db = CurrentDb
    
    Set rs = db.OpenRecordset("ActualTableOrQueryName")
    
    If cmdTickAllBoxes.Caption = "Tick All" Then
      
     cmdTickAllBoxes.Caption = "Untick All"
     
     Do While Not rs.EOF
      rs.Edit
      rs!CheckboxField = -1
      rs.Update
      rs.MoveNext
     Loop
    
    Else
    
     cmdTickAllBoxes.Caption = "Tick All"
     
     Do While Not rs.EOF
      rs.Edit
      rs!CheckboxField = 0
      rs.Update
      rs.MoveNext
     Loop
    
    End If
    
    rs.Close
    
    Set rs = Nothing
    
    Me.Requery
    
    End Sub

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  13. #13
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    linq's code will check all the records in the table but there is simpler code to do that:

    CurrentDb.Execute "UPDATE tablename Set Profiles=True"

    However, maybe the form is filtered and not displaying all records. If you want to check only the records displayed on form, that means cycling through records of the form. Suggest using the form's RecordsetClone.

    With Me.RecordsetClone
    !Profiles = True
    .MoveNext
    End With

    Then to uncheck all records:

    CurrentDb.Execute "UPDATE tablename Set Profiles=False"
    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.

  14. #14
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by June7 View Post

    ...However, maybe the form is filtered and not displaying all records...
    Sorry, meant to add that caveat and got distracted by tremendous thunderstorm that started as I was posting! My handsome but scared-of-everything Brittany Spaniel jumped in my lap, sending my keyboard flying!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  15. #15
    khughes46 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Grapevine, TX
    Posts
    231
    LOL! I don't see a RecordsetClone. Where do I find RecordsetClone?

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

Similar Threads

  1. Multi Select Check Boxes?
    By CDavis10 in forum Forms
    Replies: 2
    Last Post: 07-19-2013, 07:04 AM
  2. Check Boxes On Form
    By Iain in forum Forms
    Replies: 14
    Last Post: 06-09-2012, 12:09 PM
  3. Check my Select Statement in Form
    By OMGsh Y did I say Yes in forum Forms
    Replies: 12
    Last Post: 12-07-2010, 02:13 PM
  4. Filter by Form: Check Boxes.
    By tbh7x in forum Forms
    Replies: 0
    Last Post: 08-18-2010, 09:15 AM
  5. To check or Un-Check all Boxes in a form
    By devcon in forum Forms
    Replies: 7
    Last Post: 05-01-2010, 12:03 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