Solved

header checkbox to check or uncheck multiple boxes in access

Posted on 2014-01-03
11
1,379 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
 
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 34

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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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 34

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 34

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 34

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

706 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

20 Experts available now in Live!

Get 1:1 Help Now