multiple selection of check box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mmasood
    New Member
    • Apr 2010
    • 2

    #1

    multiple selection of check box

    I would like to know how i can make a multiple selection check box for e.g. like yahoo in box if you select or deselect the header check box all the below check boxes are checked or unchecked.

    In access 2007 I have one form connected to one table with a field name Present and that field have check box Yes/No, if an employee is present i will check for him and if he is absent i will uncheck, it is big job if i have hundreds of employees to track their attendance, i have created on check box on the header of the form and i want to select or deselect all the check boxes when i select or deselect the header check box.

    I would greatly appreciate if someone please help me on this

    many thanks

    best regards,
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    You could connect an update query to the checkbox (or button). That is what I would do. Whether you want to do this by macro, or code, depends on your VBA skills.

    If you need help with a VBA solution, you need to give some more information on your table structure, and your layout.

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Let's assume that your Main Check Box is named chkPresent. The following code, in the AfterUpdate() Event of chkPresent, will Check/Uncheck all Check Boxes on your Form depending on whether or not chkPresent is Checked. Is this what you are looking for?
      Code:
      Private Sub chkPresent_AfterUpdate()
      Dim ctl As Control
      
      For Each ctl In Me.Controls
        If ctl.ControlType = acCheckBox Then
          If ctl.Name <> "chkPresent" Then
            ctl.Value = Me![chkPresent].Value
          End If
        End If
      Next
      End Sub

      Comment

      • mmasood
        New Member
        • Apr 2010
        • 2

        #4
        Dear Sir,
        Foremost, many thanks for the prompt reply, i tryed this code in afterupdate event of my main checkbox but it checks only the cehck box which got the focus

        here is my table sturcture design

        StudentID - AutoNumber
        EmpID-Number
        StudentName - Text
        TempAttendance-Yes/No
        OT-Text

        would apprecaite again some more help on this

        with kind and best regards,

        Comment

        • TheSmileyCoder
          Recognized Expert Moderator Top Contributor
          • Dec 2009
          • 2322

          #5
          In the afterUpdate event of the checkbox:
          Code:
          Docmd.SetWarnings(False)
            Docmd.Runsql("UPDATE tbl_Students SET TempAttendance = " & Me.ChckBox);
          Docmd.SetWarnings(True)
          Note that this will set the TempAttendence field for ALL records in teh table. If you need to only do it for some records, you will need to add a WHERE clause.

          Comment

          Working...