Results 1 to 12 of 12
  1. #1
    TheHarleygirl2005 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    34

    Select All/ Clear All checkbox


    I have a form that lists approximately 100 companies and a checkbox for each company. It is set up so a supervisor can check several companies then hit a command button that appends those records to a table (using an append query). Sometimes a supervisor only needs to select a hand full of companies but sometimes they need to check all 100 records. Is it possible to add a command button to the form that when selected it checks all boxes on the form. I would also need a second command button that unchecks all boxes. I'm guessing this would be done by building a code under the "on click" in properties but I'm not sure what the code would be for that.

    OR

    Would I create an unbound checkbox that I would check to select all and uncheck to clear all?

  2. #2
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536
    I imagine you could use a process similar to this one to check and uncheck all the boxes.

    http://www.datapigtechnologies.com/f...tboxtrick.html

    Alan

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,601
    Give the 100 checkboxes similar names, like chkSupv1, chkSupv2, etc. Also, labels with similar names that contain the value you want saved, these labels be can hidden.

    For i = 1 to 100
    If Me.Controls("chkSupv" & i) = True Then
    CurrentDb.Execute "INSERT INTO tablename(fieldname) VALUES(" & Me.Controls("lblSupv" & i) & ")"
    End If
    Next

    Similar code to set the checkbox and yes another checkbox (or a toggle button) for the select all/clear all could work.

    For i = 1 to 100
    Me.Controls("chkSupv" & i) = Me.chkSelect
    Next
    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.

  4. #4
    TheHarleygirl2005 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    34
    I don't have 100 different check boxes. I have one field named "SchoolsOut" in the company table which is a Yes/No field.
    Click image for larger version. 

Name:	SchoolsOut.jpg 
Views:	29 
Size:	150.4 KB 
ID:	10678

    I have set up the form so the supervisor adds a date (in the footer) and checks the appropriate box(s) then runs the append query by hitting the "Go" button to dump the data into a table which shows the selections for each date.

    I'm just looking for away to check all the boxes or uncheck all the boxes in this form. It doesn't have to update or append because the go button takes care of that.

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,601
    Yes, that gives me a very different understanding than 'a checkbox for each company'. There is only one checkbox bound to Yes/No field.

    Probably the easiest way to select/unselect all is with an UPDATE sql action and refresh the form.

    Another way is for code to physically move to each record and set the checkbox value. This gets tricky for detecting the begin/end of the records. I have never done code for this.

    A method I do use frequently is looping through the form's RecordsetClone.
    While Not Me.RecordsetClone.EOF
    Me.RecordsetClone!SchoolOut = Me.chkSelect
    Me.RecordsetClone.MoveNext
    Wend
    Me.Refresh
    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
    TheHarleygirl2005 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    34
    Okay, I added a Command Button and put the following code in the "on Click" procedure:

    Private Sub Command25_Click()
    On Error GoTo Err_Command25_Click
    Me.TempAttendance.Value = "True"
    Me.Requery
    Exit_Command25_Click:
    Exit Sub
    Err_Command25_Click:
    MsgBox Err.Description
    Resume Exit_Command25_Click

    End Sub



    This code only adds a check to the first record, not the following 99. What did I do wrong?

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,601
    Because the code does not loop and move to next record. Review my previous post.
    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.

  8. #8
    TheHarleygirl2005 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    34
    I tried to use your previous post but it did not work which is why went with this. When I use the following code I get an error.

    Click image for larger version. 

Name:	Error.jpg 
Views:	27 
Size:	71.6 KB 
ID:	10737

    While Not Me.RecordsetClone.EOF
    Me.RecordsetClone! TempAttendance= Me.chkSelect
    Me.RecordsetClone.MoveNext
    Wend
    Me.Refresh

    The control source for Schools Out? is called "TempAttendance"

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,601
    You need an unbound checkbox or toggle button in the form header that will be used as criteria for the value to set all the records. That would be called chkSelect. You can put the code in the AfterUpdate event of that control.
    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
    TheHarleygirl2005 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    34
    Okay, I deleted the Command Button and added a checkbox to the header with the following code from above:

    Private Sub chkSelect_AfterUpdate()
    While Not Me.RecordsetClone.EOF
    Me.RecordsetClone!TempAttendance = Me.chkSelect
    Me.RecordsetClone.MoveNext
    Wend
    Me.Refresh

    End Sub


    I now get a Run-Time error 3020 "Update or Cancel update without AddNew or Edit

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,601
    Oh nuts! Forgot the Edit. I use RecordsetClone a lot to read data from a form but rarely to edit. I normally would use sql UPDATE action to mass edit records.

    With Me.RecordsetClone
    .MoveFirst
    While Not .EOF
    .Edit
    !TempAttendance = Me.chkSelect
    .Update
    .MoveNext
    Wend
    End With
    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.

  12. #12
    TheHarleygirl2005 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    34
    Thank you! Thank you! Thank you! This is perfect!

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

Similar Threads

  1. Clear field
    By Fortfury in forum Forms
    Replies: 1
    Last Post: 12-28-2012, 08:20 PM
  2. clear form
    By slimjen in forum Forms
    Replies: 1
    Last Post: 05-16-2012, 02:53 PM
  3. clear checkbox and list box using TypeOf......Is
    By Chuck55 in forum Programming
    Replies: 13
    Last Post: 04-06-2012, 08:21 PM
  4. Clear some fields and not others
    By funkygoorilla in forum Access
    Replies: 12
    Last Post: 08-23-2011, 07:38 AM
  5. Replies: 3
    Last Post: 05-15-2011, 10:52 PM

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