Selecting all Checkboxes within an option Group

modest_16081982

New member
Local time
Today, 11:57
Joined
Aug 15, 2007
Messages
4
hi,

I am designing a form which has an option group with 4 checkboxes. What I am looking for is that if there is any way by which whenever I click on "All Degree" check box it should check all the other check boxes (Engineering, Medicine, Business). Also I should be able to check any combination of those checkboxes. How can I do it? I am not an expert in Access but I do understand the basics of access.

I am attaching the file "test.mdb" in the test.zip file attached with this post . Please look at the form "Search" and all will make sense.

Your help will be greatly appreciated.

Thanks
 

Attachments

An Options Group is designed to be only one selection allowed. Selecting something else within the group unselects all other selections. There is no native group that will do what you want but you can build your own with a rectangle and check boxes. Name your CheckBoxes in a numerical sequence like cb1, cb2...etc and it will be easy to write code to select them all if that is what you want to do.
 
An Options Group is designed to be only one selection allowed. Selecting something else within the group unselects all other selections. There is no native group that will do what you want but you can build your own with a rectangle and check boxes. Name your CheckBoxes in a numerical sequence like cb1, cb2...etc and it will be easy to write code to select them all if that is what you want to do.

Thanks for your reply. Actually I am not very familiar writing code in access. Can you give me some kind of pointer/sample which demonstrates that?

Once again. Thanks a lot for your reply...
 
Here is what I am trying to do:

Code:
Option Compare Database

Private Sub cbAll_Click()
cb2.InSelection = True
cb2.InSelection = True
End Sub

Private Sub Detail_Click()
End Sub

Where cbAll is the name of my "Select All" checkbox and rest of them are regular options. But for some reason it is giving me an error "Property available only in design view"....

:(
 
Try this << UNTESTED AIR CODE >>
Code:
Private Sub cbAll_Click()
'-- Turn all of the cb's on or off depending on whether cbAll is checked or unchecked.
Dim LoopIndex As Integer
For LoopIndex = 1 To 8 '-- Or however many cb's you have named
   '-- This will check/uncheck cb1,cb2,cb3,cb4,cb5,cb6,cb7,cb8
   Me.Controls("cb" & LoopIndex) = Me.cbAll
Next LoopIndex

End Sub
This code should give you an idea how to make it work. Post back if you need further assistance.
 
Try this << UNTESTED AIR CODE >>
Code:
Private Sub cbAll_Click()
'-- Turn all of the cb's on or off depending on whether cbAll is checked or unchecked.
Dim LoopIndex As Integer
For LoopIndex = 1 To 8 '-- Or however many cb's you have named
   '-- This will check/uncheck cb1,cb2,cb3,cb4,cb5,cb6,cb7,cb8
   Me.Controls("cb" & LoopIndex) = Me.cbAll
Next LoopIndex

End Sub
This code should give you an idea how to make it work. Post back if you need further assistance.

Thanks for the code. That's awesome.. I will try that soon....Many thanks once again....:)
 
Good luck. Post back if you need further assistance.
 
I'll throw in another way of doing it as well, just as an alternative method. For anyone like me who likes to have specific meaningful names to their controls (no cb1, cb2, etc for me, unless I absolutely have to). I use the TAG property to loop through and set things.

To do so, I put something in the tag property, such as SelectALL and then I use:
Code:
Dim ctl As Control

For Each ctl In Me.Controls
  If ctl.Tag = "SelectALL" Then
     ctl.Value = True
  End If
Next ctl

So, for the After Update event of the ALL checkbox I would have:

Code:
Dim ctl As Control

For Each ctl In Me.Controls
  If ctl.Tag = "SelectALL" Then
     ctl.Value = Me.cbALL
  End If
Next ctl



So, anyway I just thought I would throw that out there as I use that way quite a bit, depending on what I want to accomplish.
 
How do I select all checkboxes?

Hi,

I have a similar case where I need to deselect all checkboxes of the subform by clicking a button on the main form.

The records in the subform are from a query that filters records for Selected = true. This can be a few thousand records so the user needs an option to deselect all and then select the desired ones.

In other words I just want all the checkboxes on the subform to be unchecked when the user clicks on the button and I don't want to loop through a recordset and update the records yet.

I have written this code but it does it only for the first record. Can anyone tell me how it can be done for all

Private Sub cmdCheckAll_Click()
For Each ctrl In subForm.Controls
If ctrl.Name = "Selected" Then
ctrl.Value = 0
End If
Next
End Sub

Any help or direction is highly appreciated.
Cheers
 
In other words I just want all the checkboxes on the subform to be unchecked when the user clicks on the button and I don't want to loop through a recordset and update the records yet.
If your SubForm is in Continuous form mode, which I suspect it is, then an update query is in order.
 
How to deselect all checkboxes in subform

Hi,

Thanks for the reply. However my problem is not sorted yet. I suppose I didn't explain the case too well.

My subform has controls in 'datasheet' format (tried continuous forms too) with over 2000 records.
This is a list of letters to be sent from a query that has a Yes/No field called Selected. The list is filtered for records that have "Selected" field = -1.
The user narrows down the list by de-selecting the "Selected" field and pressing a button to refresh the list.

This functionality works fine, what I need now is to provide an option for the user to click a button to de-select all the records in the list since it is easier to select 4-5 that are required rather than deselect around 2000 records.

The code that I posted earlier does what I need but only for the current record where the cursor points.

This could be a simple thing for you Access experts in this forum, but I can't seem to figure out a solution for this.
Any suggestions??
Thanks for your help.
 
deselect all checkboxes in subform

Hi,

Thanks for the reply. However my problem is not sorted yet. I suppose I didn't explain the case too well.

My subform has controls in 'datasheet' format (tried continuous forms too) with over 2000 records.
This is a list of letters to be sent from a query that has a Yes/No field called Selected. The list is filtered for records that have "Selected" field = -1.
The user narrows down the list by de-selecting the "Selected" field and pressing a button to refresh the list.

This functionality works fine, what I need now is to provide an option for the user to click a button to de-select all the records in the list since it is easier to select 4-5 that are required rather than deselect around 2000 records.

The code that I posted earlier does what I need but only for the current record where the cursor points.

This could be a simple thing for you Access experts in this forum, but I can't seem to figure out a solution for this.

Show me the light!! Thanks for your help.
 
Try the following query:
UPDATE YourTable SET YourTable.Selected = False;
...using YourTable name of course. Then Requery the SubForm.
 
Hi RG,
I already use that query to filter the list and that part works fine. However what I need is for all records to be unchecked on the screen without updating the table.
The process that my program follows is below:

1. Display list of records where selected=true --> Works
2. Provide option to uncheck all records only on screen without requery --> Does not work.
3. Allow user to select required records and click on button to requery --> Works

Is there a way to do option 2 by modifying the code below:

Private Sub cmdCheckAll_Click()
For Each ctrl In subForm.Controls
If ctrl.Name = "Selected" Then
ctrl.Value = 0
End If
Next
End Sub

Thanks
 
If the "selected checkboxes" on the records in the SubForm are bound to the field in the RecordSource of the SubForm then unchecking them without affecting the recordset is *not* an option.
 
Hi RG,
I agree, however when I uncheck each checkbox manually, the form does not requery automatically which is good.
I want to provide an option to unckeck all (without clicking each manually) and then click my button that requeries and displays only the selected ones.
Cheers.
 

Users who are viewing this thread

Back
Top Bottom