473,672 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Checkbox selects other Checkboxes

beacon
579 Contributor
Hi everybody,

[Access 2003]

I have a quality assurance database that has a form with a bunch of checkboxes on it that serve as reasons for why a product didn't pass inspection.

It's a given that the users will be able to select individual checkboxes to indicate the reasons. What I would like to find out how to do is to put a checkbox or radio button on the form that will select all the checkboxes if it's selected.

When I added a checkbox to my form and tried to write code for it, the control didn't have a 'Value' or 'Checked' property for me to choose. Is it not possible to do this? If I use a radio button, I'd like to have one to 'Select All' and one to 'Deselect' if at all possible.

I tried the following to no avail based on something I found online:
Expand|Select|Wrap|Line Numbers
  1. Private Sub chkSelectAll_AfterUpdate()
  2. me.chkDefect = me.chkSelectAll
  3. me.chkPowerSupply = me.chkSelectAll
  4. end sub
  5.  
Can anyone share a little help with me?

Thanks in advance,
beacon
Jan 20 '09 #1
13 2553
OldBirdman
675 Contributor
Expand|Select|Wrap|Line Numbers
  1. me!chkDefect = me!chkSelectAll
  2. me!chkPowerSupply = me!chkSelectAll
  3.  
You do not need a 'Deselect' as all will be deselected if/when chkSelectAll is clicked again, and is then false.
It makes no difference whether you use checkboxes or radiobuttons. However, radiobuttons imply that only one can be true at any given time. Radio button refers to a radio presets, and selecting a station deselects another. I assume that a product can fail for multiple reasons simultaneously, and therefore checkboxes would be my preference.

OldBirdman
Jan 21 '09 #2
beacon
579 Contributor
Hi OldBirdMan,

Here's the code I entered for my 'Select All' checkbox. I don't think it matters, but the checkboxes are all on a tab control.

Expand|Select|Wrap|Line Numbers
  1. Private Sub chkSelectAll_AfterUpdate()
  2. me.chkDefect = me.chkSelectAll
  3. End Sub
  4.  
When I enter this and go back to use the 'Select All' checkbox, I get an error message that says, "Run-time error 438: Object doesn't support this method or property."

This is the error message I was getting initially that prompted me to post to the forum. I don't use checkboxes that often and this is the first time I've tried to control other checkboxes with a checkbox.
Jan 21 '09 #3
NeoPa
32,569 Recognized Expert Moderator MVP
Hi OB. Good to see you around again :)

Assuming the clever naming structure that OB displays in his example (All CheckBox controls, and only CheckBox controls, start chk) and also that chkSelectAll & chkDeselectAll are the only ones ending in the last three characters "All", then the following code should help somewhat :
Expand|Select|Wrap|Line Numbers
  1. Private Sub chkSelectAll_AfterUpdate()
  2.   Call SetAll(blnValue:=True
  3. End Sub
  4.  
  5. Private Sub chkDeselectAll_AfterUpdate()
  6.   Call SetAll(blnValue:=False
  7. End Sub
  8.  
  9. Private Sub SetAll(blnValue As Boolean)
  10.   Dim ctlThis As Form.Control
  11.  
  12.   For Each ctlThis In Me.Controls
  13.     If Left(ctlThis.Name, 3) = "chk" _
  14.     And Right(ctlThis.Name, 3) <> "All" Then _
  15.       ctlThis = blnValue
  16.   Next ctlThis
  17. End Sub
Jan 21 '09 #4
NeoPa
32,569 Recognized Expert Moderator MVP
@beacon
This is because the items you're dealing with are objects whose default property is .Value.

When mixed with other items (EG. Me.chkDefect = blnValue) it determines the default property to be required. When used object to object (as here) it thinks you want to assign one object to the other (EG. Set objVar = Me.chkSelectAll ).

Does that clarify your understanding?
Jan 21 '09 #5
FishVal
2,653 Recognized Expert Specialist
@beacon
That only means Me object doesn't support either chkDefect or chkSelectAll property, most probably chkDefect.
Jan 21 '09 #6
beacon
579 Contributor
@NeoPa
I understand what you're saying, but I'm not sure how to rectify the problem. I saw your response that showed how I could loop through each of the controls based on the 'chk' prefix, but it brings up another potential issue I'll undoubtedly run into.

The potential issue is how can I handle this problem if I'm asked to put in another checkbox that allows the user to select default reasons. For instance, we have 'Select All' that chooses all of the checkboxes and we have a 'Select Default' that only chooses a certain selection based on the product type...how can I indicate just a select few to be selected when that option is chosen?

Keep in mind that there are multiple different products so the options will be different for 'Select Default' based on the product.
Jan 21 '09 #7
OldBirdman
675 Contributor
No, it doesn't clear up anything. It seems like I assign .value to .value all the time. txtA = txtB, chkC = chkD, or txtE = cboF, etc. Never had any issues here with Access making the assignments. Because this code is in the form's module, can't the "me" be dropped completely?

Clever naming structure belongs to beacon's original post, I kept answers in his framework, but it is similar to my naming conventions.

As to having a "DeSelectAl l" checkbox, the code shown does not clear it when "SelectAll" is checked. Reflecting on this, I don't think there should be either a Select or DeSelect checkbox. They should be command buttons, "Select All" and "Clear All".

If a product is defective in all categories except 1, user might want to select all, and then deselect it (i.e. uncheck chkPowerSupply) to show that it passed the one test. The chkSelectAll is now incorrect if it means that all checkboxes are checked. It gets more complicated because, after each individual checkbox is changed, all must be checked to see if either chkSelectAll or chkDeSelectAll should be changed. chkSelectAll = (chkPowerSupply And chkDefect . . .) and DeSelectAll = Not (chkPowerSupply Or chkDefect Or . . .). This could be done in a loop similar to that shown in Post #4 by NeoPa.

This could be expanded to include a "Default" command button. (This discussion is now about sets of checkboxes, not the actual problem presented, as something is very wrong if there is a "Default" set of flaws in a product. Improve your quality control, or get a new supplier). Each item would have a Default set of flaws.

Checkboxes would have to be TripleState, and locked if grayed, or Checkboxes would vary from item to item. You might consider a subform with each record showing an inspection item and a checkbox. This is a database design issue.

OldBirdman
Jan 21 '09 #8
beacon
579 Contributor
I think I found my answer on this website: ** Edit ** link removed.

In case you don't want to go to the website, the gist of the solution is to enter a tag for each of the checkboxes I want selected (All or default) and then create an AfterUpdate() event for the checkbox that will trigger the event.

Here's the code assuming that I put a tag of 'SelectAll' or 'Default' in for the checkboxes that I want controlled by the chkSelectAll or chkDefault:
Expand|Select|Wrap|Line Numbers
  1. Private Sub chkSelectAll_AfterUpdate()
  2.     Dim ctl as Control
  3.  
  4.     For Each ctl In Me.Controls
  5.         If Me.chkSelectAll = True Then
  6.             If ctl.Tag = "SelectAll" Then
  7.                 ctl.Value = True
  8.             End If
  9.         Else
  10.             If ctl.Tag = "SelectAll" Then
  11.                 ctl.Value = False
  12.             End If
  13.         End If
  14.     Next ctl
  15. End Sub
  16.  
This will check only the boxes that you've entered a tag for. I took the code I found and took it one step further by adding the conditional "If Me.chkSelectAll = True" around the other conditional "If ctl.Tag = 'SelectAll'..." which allows you to deselect your selection.

I don't really understand how I was able to give a ctl a .Value when it wasn't available from the properties when I typed in the code, but it works. I know that you can't just type the following:
Expand|Select|Wrap|Line Numbers
  1. If ctl.Tag = "SelectAll" Then
  2.      ctl.Value = True
  3. Else
  4.      ctl.Value = False
  5. End If
  6.  
...because it will give you an error message similar to the runtime error 438 I was receiving when I initially began this process.

You have to put in some work to add the tags to each of the checkboxes, but once you get that entered it works pretty well.

Thanks for everybody's input...
Jan 21 '09 #9
NeoPa
32,569 Recognized Expert Moderator MVP
@beacon
As it seems you have already discovered, a good way to track this when the conditions are not as simple as those stipulated, is to use the Tag property of a control. Any value could be used for the tag simply to identify which are grouped together :
Expand|Select|Wrap|Line Numbers
  1. Private Sub SetAll(blnValue As Boolean) 
  2.   Dim ctl As Form.Control 
  3.  
  4.   For Each ctl In Me.Controls 
  5.     If ctl.Tag = "Group1" Then ctl = blnValue 
  6.   Next ctl 
  7. End Sub
Jan 21 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
4433
by: newjazzharmony | last post by:
Hello group, I want to automatically select a specific checkbox when a user clicks (selects) a specific item in a radiobutton group. Both controls are in the same form. Let's say for argument's sake that the form looks like this (inessential items left out for the sake of clarity): <form name=form1>
3
6729
by: delram | last post by:
I'm trying to get user selections (using checkboxes) on one JSP page(A.jsp) and pass them on to another page. So I have one page with a list of dynamically populated items like this 1 2 ... ... n
3
3681
by: uremog | last post by:
I have a set of of check boxes. onClick, the checkboxes call check_radio and recup_checkbox. the referenced radios function as group selectors. check_radio just unchecks the radios if someone manually selects checkboxes. i think the problem is in the add_selection and del_selection as suggested by the alerts, which are for debugging only. it gets as far as the alert(add/del selection) alerts in FF. all the alert tests pass in IE. as...
2
20992
by: =?Utf-8?B?UmljaA==?= | last post by:
Is there a cancel argument for cancelling if you want to check or uncheck a checkbox? In the checkChanged event of a checkbox I ask the user if they are sure they want to check/uncheck something. If No, I want to cancel the check or uncheck and cancel the click event. Right now I have a form level boolean checkvar that I set based on the user's response. If No then when entering the click event I don't perform various actions. Is...
2
5418
by: dkultasev | last post by:
Hello, I have small script which generates some listboxes. Their names are listXX (list01, list02, list03....). How to check if there are checked or not ? If I have 1 listbox and have it's name I do $_POST. But what to do in that situation ? Sincerely, Dmitrij
0
8486
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8931
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8608
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8680
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7446
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5705
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4418
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.