Solved

header checkbox to check or uncheck multiple boxes in access

Posted on 2014-01-03
11
1,445 Views
Last Modified: 2014-05-12
I would like to know how i can make a multiple selection check box to select or deselect the header check box all the below check boxes are checked or unchecked.
 
In access 2007 I have one subform connected with fields have check box Yes/No for taking attendance.  When the form opens, all boxes are checked.  If a student is absent i will uncheck, it is big job if i have hundreds of students to track their attendance.  i want to create a check box on the header of the form for each row and column to select or deselect all the check boxes in the column or row and uncheck or check.
 
I would greatly appreciate if someone please help me on this
0
Comment
Question by:softsupport
  • 4
  • 4
  • 3
11 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 39754816
In the after update event of the checkbox on the main form:


Dim rs as DAO.recordset
Set rs = Me.MysubformName.form.recordsetclone
if rs.recordcount = 0 then exit sub

with rs
do until .eof
     !MyYesNoField = Me.MyMainFormCheckboxName
     .movenext
loop

set rs = nothing

Open in new window

0
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 300 total points
ID: 39754829
The above is assuming that the "Check all" box is located in a main form and the individual check boxes are in a subform.

If the "Check All" box is located in the header section of the same form as the checkboxes you want to check/uncheck, then modify that code like this:
Dim rs as DAO.recordset
Set rs = Me.recordsetclone
if rs.recordcount = 0 then exit sub

with rs
do until .eof
     !MyYesNoField = Me.MyCheckAllCheckboxName
     .movenext
loop

set rs = nothing

Open in new window

0
 

Author Comment

by:softsupport
ID: 39754923
Not sure if I was clear on question.  I have several students, and 31 days in the month.  If all students are absent on the 25th (Christmas), I want to select the column or header checkbox and unselect all students for the 25th.  If one student is absent the entire month (31 days), I want to select the student name on left of grid and unselect all 31 days.  Will either of the above accomplish this task?
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 61

Expert Comment

by:mbizup
ID: 39755030
I believe the second method will work for what you are describing, but obviously I don't have your database to verify.

Give it a try, and post back if you run into any trouble with it.

Posting a sample database would also help clarify if you need to.
0
 
LVL 35

Expert Comment

by:PatHartman
ID: 39755438
Your table is not normalized. or the whole thing could be done with a simple query.  As it is, you will need to implement checking a "row" by using code and checking a "column" will need both a little code plus a query.

To do the row, add an unbound checkbox to the subform.  In the click event of the control, set the value for each field appropriately.

Me.fld1 = me.chk
Me.fld2 = Me.chk
Me.fld3 = Me.chk
....

Open in new window

For the columns, add an unbound checkbox in the subform header for each column.

In the click event of each column checkbox, run an update query.
Dim strSQL as String
strSQL = "Update yourtable Set somefield = " & Me.ColChk1 
strSQL = strSQL & " WHERE  somecriteria that selects the correct records"
DoCmd.RunSQL strSQL

Open in new window

Change the variables for  each column.
0
 

Author Comment

by:softsupport
ID: 39760381
In regards to the solution listed above:
What should the "!MyYesNoField" and "Me.MyMainFormCheckboxName" be?  

Dim rs as DAO.recordset
Set rs = Me.MysubformName.form.recordsetclone
if rs.recordcount = 0 then exit sub

with rs
do until .eof
     !MyYesNoField = Me.MyMainFormCheckboxName
     .movenext
loop

set rs = nothing
0
 
LVL 35

Accepted Solution

by:
PatHartman earned 200 total points
ID: 39760520
!MyYesNoField = Me.MyMainFormCheckboxName

You need to have as many of these statements as you have columns you want to set.  Change !MyYesNoField to the actual column names.

Me.MyMainFormCheckboxName probably needs to be  Me.Parent!MyMainFormCheckboxName and you need to change the name to reflect the name of the control you are using to control the setting.

Also, the suggested code will update ALL rows of the recordsetclone of the subform and so won't work to update all the columns of a single row unless you modify it to locate the record you want to update.
0
 

Author Comment

by:softsupport
ID: 39766275
I am receiving an error message.... See attached.
VBA-Error.jpg
0
 
LVL 35

Expert Comment

by:PatHartman
ID: 39766301
You posted the code but not the error message.

The code looks like it will only set a field named [1], if it works at all.
0
 

Author Comment

by:softsupport
ID: 39766467
Apologies.... Here is the error
VBA-Error002.jpg
0
 
LVL 35

Assisted Solution

by:PatHartman
PatHartman earned 200 total points
ID: 39767132
That is a pretty straight forward error.

With begins a block of code.  You need an End With to end it.

with rs
do until .eof
     !MyYesNoField = Me.MyMainFormCheckboxName
     .movenext
loop
End With

Open in new window

0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now