Solved

header checkbox to check or uncheck multiple boxes in access

Posted on 2014-01-03
11
1,567 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
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 37

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 37

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 37

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 37

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

724 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