?
Solved

header checkbox to check or uncheck multiple boxes in access

Posted on 2014-01-03
11
Medium Priority
?
1,628 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 1200 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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 38

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 38

Accepted Solution

by:
PatHartman earned 800 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 38

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 38

Assisted Solution

by:PatHartman
PatHartman earned 800 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
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…
Suggested Courses

777 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