473,394 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Checkbox selects other Checkboxes

beacon
579 512MB
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 2539
OldBirdman
675 512MB
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 512MB
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,556 Expert Mod 16PB
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,556 Expert Mod 16PB
@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 Expert 2GB
@beacon
That only means Me object doesn't support either chkDefect or chkSelectAll property, most probably chkDefect.
Jan 21 '09 #6
beacon
579 512MB
@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 512MB
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 "DeSelectAll" 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 512MB
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,556 Expert Mod 16PB
@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
NeoPa
32,556 Expert Mod 16PB
@OldBirdman
Well, it seems Fish thinks I may be mistaken too. Possibly true. I'm a bit rushed at the moment to set up a test, but it's not too hard. Check it out.
@OldBirdman
Yes. It can. That doesn't mean it's a good idea though. Me. is more explicit, thus making the code clearer to a reader. Certainly not necessary though.
@OldBirdman
Good point, and good solution.
Jan 21 '09 #11
NeoPa
32,556 Expert Mod 16PB
@beacon
Sorry about that. Our rules forbid linking to competing forums. We suffer enough from spam, and that would just make it too easy. I suspect your usage was innocently enough intended, but it had to be removed nevertheless.
@beacon
If ctl is Dimmed as a simple Form.Control, then this makes sense. Intellisense.

Intellisense (prompting you with a list of available properties) can only prompt with what it knows about. If the variable had been designed as a Form.CheckBox, then it would have known it had a .Value property. As it is defined as a generic control then it doesn't know that.

Your code wouldn't work as written if your form had any controls without the .Value property (EG. Label).

PS. Please check out OB's post where he suggests using command buttons instead of checkboxes for this. He makes a good point.
Jan 21 '09 #12
beacon
579 512MB
Hi NeoPa,

Sorry about the link...I questioned whether or not I should include. I'm really in the habit of including my sources for school and thought it best to give credit where it's due. Thanks for clearing that up...I won't include links to other forums in the future.

I read what OB said about the command buttons and I tried that, but I didn't have any luck initially...I still got the 438 error message.

Now that I've gotten the solution I listed...I guess it really doesn't matter if I use a checkbox or a command button. The checkbox will add or remove checks from the other checkboxes depending on whether or not it's value is true or not, so it basically serves the same purpose as a select/clear command button. Heck, a toggle button that changed it's caption from 'Select' to 'Clear' might even be neat/useful.

My task, now that the checkboxes work for default and select all conditions, is to find a way to link the default reason to the product that's chosen. I don't think I'll have any problems...just a lot of repetitive code to address all the possible conditions.

Thanks again, as always, for all your help...
Jan 21 '09 #13
NeoPa
32,556 Expert Mod 16PB
@beacon
Really not a problem. I guessed as much. Incidentally, links to sites hosted by the provider will always be acceptable (MSDN for instance, or an MS web page for Access).

Oh, and have fun with your tagging ;)
Jan 22 '09 #14

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

Similar topics

3
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...
3
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 ...
3
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...
2
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...
2
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.