473,396 Members | 2,129 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,396 software developers and data experts.

Enable and disable checkbox

Hi,I have say 10 checkbox in my form. In which i should be able to select only 2 checkboxes. Once 2 checkbox are selected then the remaining checkboxes should be disabled. And which ever checkboxes are selected, those checkboxes should fetch the data from the different excel sheets and place it in the 2 frames which are designed below.(Each frames consists of some more checkbox. But i am facing the issue when the checkbox are checked.

Please help me developing this.


Thanks
Jan 5 '12 #1

✓ answered by Guido Geurs

This code will disable the checkboxes when 2 of them are selected.
When one of the selected is unchecked: all the checkboxes are again available.

Expand|Select|Wrap|Line Numbers
  1. Private Sub CheckBox1_Change()
  2.     If CheckBox1.Value = False Then
  3.         Call Enable_All
  4.     Else
  5.         Call Disable_All
  6.     End If
  7. End Sub
  8.  
  9. Private Sub CheckBox2_Change()
  10.     If CheckBox2.Value = False Then
  11.         Call Enable_All
  12.     Else
  13.         Call Disable_All
  14.     End If
  15. End Sub
  16.  
  17. Private Sub CheckBox3_Change()
  18.     If CheckBox3.Value = False Then
  19.         Call Enable_All
  20.     Else
  21.         Call Disable_All
  22.     End If
  23. End Sub
  24.  
  25. Private Sub CheckBox4_Change()
  26.     If CheckBox4.Value = False Then
  27.         Call Enable_All
  28.     Else
  29.         Call Disable_All
  30.     End If
  31. End Sub
  32.  
  33.  
  34. Private Sub CheckBox5_Change()
  35.     If CheckBox5.Value = False Then
  36.         Call Enable_All
  37.     Else
  38.         Call Disable_All
  39.     End If
  40. End Sub
  41.  
  42. Private Sub CheckBox6_Change()
  43.     If CheckBox6.Value = False Then
  44.         Call Enable_All
  45.     Else
  46.         Call Disable_All
  47.     End If
  48. End Sub
  49.  
  50. Private Sub CheckBox7_Change()
  51.     If CheckBox7.Value = False Then
  52.         Call Enable_All
  53.     Else
  54.         Call Disable_All
  55.     End If
  56. End Sub
  57.  
  58. Private Sub CheckBox8_Change()
  59.     If CheckBox8.Value = False Then
  60.         Call Enable_All
  61.     Else
  62.         Call Disable_All
  63.     End If
  64. End Sub
  65.  
  66. Private Sub CheckBox9_Change()
  67.     If CheckBox9.Value = False Then
  68.         Call Enable_All
  69.     Else
  70.         Call Disable_All
  71.     End If
  72. End Sub
  73.  
  74. Private Sub CheckBox10_Change()
  75.     If CheckBox10.Value = False Then
  76.         Call Enable_All
  77.     Else
  78.         Call Disable_All
  79.     End If
  80. End Sub
  81. Private Sub Disable_All()
  82. Dim CHECKEDcount As Integer
  83.     If CheckBox1.Value = True Then CHECKEDcount = CHECKEDcount + 1
  84.     If CheckBox2.Value = True Then CHECKEDcount = CHECKEDcount + 1
  85.     If CheckBox3.Value = True Then CHECKEDcount = CHECKEDcount + 1
  86.     If CheckBox4.Value = True Then CHECKEDcount = CHECKEDcount + 1
  87.     If CheckBox5.Value = True Then CHECKEDcount = CHECKEDcount + 1
  88.     If CheckBox6.Value = True Then CHECKEDcount = CHECKEDcount + 1
  89.     If CheckBox7.Value = True Then CHECKEDcount = CHECKEDcount + 1
  90.     If CheckBox8.Value = True Then CHECKEDcount = CHECKEDcount + 1
  91.     If CheckBox9.Value = True Then CHECKEDcount = CHECKEDcount + 1
  92.     If CheckBox10.Value = True Then CHECKEDcount = CHECKEDcount + 1
  93.     If CHECKEDcount > 1 Then
  94.         If CheckBox1.Value = False Then CheckBox1.Enabled = False
  95.         If CheckBox2.Value = False Then CheckBox2.Enabled = False
  96.         If CheckBox3.Value = False Then CheckBox3.Enabled = False
  97.         If CheckBox4.Value = False Then CheckBox4.Enabled = False
  98.         If CheckBox5.Value = False Then CheckBox5.Enabled = False
  99.         If CheckBox6.Value = False Then CheckBox6.Enabled = False
  100.         If CheckBox7.Value = False Then CheckBox7.Enabled = False
  101.         If CheckBox8.Value = False Then CheckBox8.Enabled = False
  102.         If CheckBox9.Value = False Then CheckBox9.Enabled = False
  103.         If CheckBox10.Value = False Then CheckBox10.Enabled = False
  104.     End If
  105. End Sub
  106. Private Sub Enable_All()
  107.         CheckBox1.Enabled = True
  108.         CheckBox2.Enabled = True
  109.         CheckBox3.Enabled = True
  110.         CheckBox4.Enabled = True
  111.         CheckBox5.Enabled = True
  112.         CheckBox6.Enabled = True
  113.         CheckBox7.Enabled = True
  114.         CheckBox8.Enabled = True
  115.         CheckBox9.Enabled = True
  116.         CheckBox10.Enabled = True
  117. End Sub

14 13558
Guido Geurs
767 Expert 512MB
This code will disable the checkboxes when 2 of them are selected.
When one of the selected is unchecked: all the checkboxes are again available.

Expand|Select|Wrap|Line Numbers
  1. Private Sub CheckBox1_Change()
  2.     If CheckBox1.Value = False Then
  3.         Call Enable_All
  4.     Else
  5.         Call Disable_All
  6.     End If
  7. End Sub
  8.  
  9. Private Sub CheckBox2_Change()
  10.     If CheckBox2.Value = False Then
  11.         Call Enable_All
  12.     Else
  13.         Call Disable_All
  14.     End If
  15. End Sub
  16.  
  17. Private Sub CheckBox3_Change()
  18.     If CheckBox3.Value = False Then
  19.         Call Enable_All
  20.     Else
  21.         Call Disable_All
  22.     End If
  23. End Sub
  24.  
  25. Private Sub CheckBox4_Change()
  26.     If CheckBox4.Value = False Then
  27.         Call Enable_All
  28.     Else
  29.         Call Disable_All
  30.     End If
  31. End Sub
  32.  
  33.  
  34. Private Sub CheckBox5_Change()
  35.     If CheckBox5.Value = False Then
  36.         Call Enable_All
  37.     Else
  38.         Call Disable_All
  39.     End If
  40. End Sub
  41.  
  42. Private Sub CheckBox6_Change()
  43.     If CheckBox6.Value = False Then
  44.         Call Enable_All
  45.     Else
  46.         Call Disable_All
  47.     End If
  48. End Sub
  49.  
  50. Private Sub CheckBox7_Change()
  51.     If CheckBox7.Value = False Then
  52.         Call Enable_All
  53.     Else
  54.         Call Disable_All
  55.     End If
  56. End Sub
  57.  
  58. Private Sub CheckBox8_Change()
  59.     If CheckBox8.Value = False Then
  60.         Call Enable_All
  61.     Else
  62.         Call Disable_All
  63.     End If
  64. End Sub
  65.  
  66. Private Sub CheckBox9_Change()
  67.     If CheckBox9.Value = False Then
  68.         Call Enable_All
  69.     Else
  70.         Call Disable_All
  71.     End If
  72. End Sub
  73.  
  74. Private Sub CheckBox10_Change()
  75.     If CheckBox10.Value = False Then
  76.         Call Enable_All
  77.     Else
  78.         Call Disable_All
  79.     End If
  80. End Sub
  81. Private Sub Disable_All()
  82. Dim CHECKEDcount As Integer
  83.     If CheckBox1.Value = True Then CHECKEDcount = CHECKEDcount + 1
  84.     If CheckBox2.Value = True Then CHECKEDcount = CHECKEDcount + 1
  85.     If CheckBox3.Value = True Then CHECKEDcount = CHECKEDcount + 1
  86.     If CheckBox4.Value = True Then CHECKEDcount = CHECKEDcount + 1
  87.     If CheckBox5.Value = True Then CHECKEDcount = CHECKEDcount + 1
  88.     If CheckBox6.Value = True Then CHECKEDcount = CHECKEDcount + 1
  89.     If CheckBox7.Value = True Then CHECKEDcount = CHECKEDcount + 1
  90.     If CheckBox8.Value = True Then CHECKEDcount = CHECKEDcount + 1
  91.     If CheckBox9.Value = True Then CHECKEDcount = CHECKEDcount + 1
  92.     If CheckBox10.Value = True Then CHECKEDcount = CHECKEDcount + 1
  93.     If CHECKEDcount > 1 Then
  94.         If CheckBox1.Value = False Then CheckBox1.Enabled = False
  95.         If CheckBox2.Value = False Then CheckBox2.Enabled = False
  96.         If CheckBox3.Value = False Then CheckBox3.Enabled = False
  97.         If CheckBox4.Value = False Then CheckBox4.Enabled = False
  98.         If CheckBox5.Value = False Then CheckBox5.Enabled = False
  99.         If CheckBox6.Value = False Then CheckBox6.Enabled = False
  100.         If CheckBox7.Value = False Then CheckBox7.Enabled = False
  101.         If CheckBox8.Value = False Then CheckBox8.Enabled = False
  102.         If CheckBox9.Value = False Then CheckBox9.Enabled = False
  103.         If CheckBox10.Value = False Then CheckBox10.Enabled = False
  104.     End If
  105. End Sub
  106. Private Sub Enable_All()
  107.         CheckBox1.Enabled = True
  108.         CheckBox2.Enabled = True
  109.         CheckBox3.Enabled = True
  110.         CheckBox4.Enabled = True
  111.         CheckBox5.Enabled = True
  112.         CheckBox6.Enabled = True
  113.         CheckBox7.Enabled = True
  114.         CheckBox8.Enabled = True
  115.         CheckBox9.Enabled = True
  116.         CheckBox10.Enabled = True
  117. End Sub
Attached Files
File Type: xls Enable and disable checkbox_v1.xls (33.0 KB, 532 views)
Jan 6 '12 #2
Killer42
8,435 Expert 8TB
Here's a simpler version. To try it out, create a new form and put an array of checkboxes on it. Then paste this code into the code area of the form. (Control arrays make your code much shorter and simpler.)
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. DefLng A-Z
  3.  
  4. ' How many are currently checked.
  5. Private NumChecked As Long
  6.  
  7. ' Maximum number that may be checked before locking.
  8. Private Const CheckLimit As Long = 2
  9.  
  10. Private Sub Check1_Click(Index As Integer)
  11.   Dim I As Long
  12.   If Check1(Index).Value Then
  13.     NumChecked = NumChecked + 1
  14.     If NumChecked >= CheckLimit Then
  15.       For I = Check1.LBound To Check1.UBound
  16.         Check1(I).Enabled = False
  17.       Next
  18.     End If
  19.   Else
  20.     NumChecked = NumChecked - 1
  21.   End If
  22. End Sub
  23.  
Jan 7 '12 #3
Thanks alot. This helped me solving the checkbox issue. But my other issue is that, Once 2 checkboxes are select i should get only data of the checkboxes selected in the frames below those 10 checkboxes.

For Example:Say 10 checkboxes are the name of the fruits, once i select 2 checkboxes i should get the data present in different sheet.

Please help me with this. And i have 2 frames in which there are checkboxes.
Jan 9 '12 #4
Guido Geurs
767 Expert 512MB
First a question: in which version are you working?
Because my solution was for Office 2003 (no indexes can be used in VBA)
or Office 2008, 2010, ...?

To get the data in the form: put the data from the sheets (columns) in an array and paste the array in the form.

Is it possible to attach your workbook in Bytes?
If it's to large, just a part of the data so we can see what your layout is and we can work on the same sheets with data.
If the information on the sheets is confidential, please enter fictive data!
Jan 9 '12 #5
Hi. I am working on Office 2010. I didnt understand how to make use of array in this case. Yes the data confidential. I will try giving you an example, you can help me to solve this issue. I will attach the file after this mail.
Jan 11 '12 #6
I have designed a simple form, which has 5 different branded clothes. Once i select 2 brands and click "Next" button, it will show the frame bellow and gets the data from the excel sheet. But i have only written the code for the first 2 check boxes. I can select any number of options bellow and click on "Go" button, in the next sheet i should to that particular and get the data. May this would help you to understand my issue. I know its a very simple code. Please help me doing this.

I am attaching a file with this reply
Attached Files
File Type: xls Enable and disable checkbox_v1.xls (55.5 KB, 445 views)
Jan 11 '12 #7
Guido Geurs
767 Expert 512MB
The checkboxes in the frames, is this for the columns to select?
Attached is a first solution.
Is this OK so far for this call?
If so, and you want more help on this project, please open an other call with an other name like "transfer data from sheets" or something like that.
This to prevent that a whole project with different problems is classified under one call with name "Enable and disable checkbox"
Attached Files
File Type: xls Enable and disable checkbox_v2.xls (59.0 KB, 496 views)
Jan 12 '12 #8
Hi. Thanks alot, it really helped me. But i have one more issue now. You remember i had sent a file from where the data is coming from different sheets. I am unable to do that. Because once the data in the first sheet changes, it should also change in the next sheet. I mean once i click on button "Go" it should get the data in the next form. Where in the selection in Frame_1_1 and Frame_1_2 can be multiple or can be individually selected. Please provide me some soultion to it.

Thanks
Jan 19 '12 #9
Hi. I have to another doubt. I have a file where the data is scattered. I have to map that data into flat format, so that it could be uploaded in the server. Doing that manually will take much time. Is it possible for you to provide any solution for this.

Thanks and Regards,
Zakeer
Jan 19 '12 #10
I am sorry i didnt read your mail properly. As i was in a hurry. And i am really very sorry for replying late. And thank you very for support.
Jan 19 '12 #11
Hi, My other doubt is i have a invoice where the data is from different sheets. In the first sheet i have total price in each module. And going forward i have different sheets where each module is break down and providing the amount for each module in detail. I have collect the data from all the sheets and populate in a single sheet, which would be flat file with all the details.

Please help me doing this.

If required i will send a example file.
Jan 20 '12 #12
Guido Geurs
767 Expert 512MB
Please open an other call with an other name like "transfer data from sheets" or something like that.
This to prevent that a whole project with different problems is classified under one call with name "Enable and disable checkbox".

In the meantime I will see what I can do.

Is it possible to attach an example of the sheets with data (e.v. with fictive values) and an example of the result you want?
Jan 21 '12 #13
Tranfer data between Sheets

Hi. Thanks alot, it really helped me. But i have one more issue now. You remember i had sent a file from where the data is coming from different sheets. I am unable to do that. Because once the data in the first sheet changes, it should also change in the next sheet. I mean once i click on button "Go" it should get the data in the next form. Where in the selection in Frame_1_1 and Frame_1_2 can be multiple or can be individually selected. Please provide me some soultion to it.
Jan 23 '12 #14
Yes sure. I will provide the example file. I shall attach that with the next mail, which i will send you.
Jan 23 '12 #15

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

Similar topics

2
by: HolaGoogle | last post by:
Hi all, Can you please tell me what's wrong with my code??? i do have this database in wich i have to field.One is a "yes/no" field and another one is "number" field. To display the yes/no field...
2
by: HolaGoogle | last post by:
Can you please tell me the right way to do this?? it's realy important! thanks in advance... Hi all, Can you please tell me what's wrong with my code??? i do have this database in wich i have...
3
by: Bob Bedford | last post by:
I've this code: function checkdate(FormSubmit){ alert(document.getElementById('Mois').value); if(eval(document.getElementById('Mois'))>0 && eval(document.getElementById('Annee'))>0){...
3
by: Alphonse Giambrone | last post by:
I am trying to enable/disable a requiredfieldvalidator on the client side and am generating an error. I had found some documentation on validation which states that I should be able to...
1
by: hortoristic | last post by:
We are using JavaScript to Enable/Disable certain fields on web pages based on business rules. A simple example is if when using an option type tag, and the two options are Yes and No. If YES...
7
by: sheldonlg | last post by:
I have a checkbox that I set by php code to be either "checked" or "". I want to disable the ability of the user to check or uncheck it. I tried "readonly", but that didn't work. Any suggestions?
2
by: RootSpy2006 | last post by:
Hi All, Problem Definition: --------------------- Microsoft Wirelss Keyboard works in BIOS but does not work when booting into windows. Discovered Work-around: -----------------------------...
2
by: Naushad | last post by:
Hi all, I am using the countinous form. I want to Enable/Disable the some fields for perticular records as per the following condition when open the form. I have written this code in "On Current...
1
by: rash007 | last post by:
I am building up a table in php built from an array in a database. I can assign each row its own id's etc. But I need to enable or disable checkbox buttons and a text area depending on the checkbox...
3
by: sanndeb | last post by:
I want to enable/disable controls of a asp.net page against a logged in user's permission. say 'admin' & 'hr' can change user's birth date text-box in a page but others will see the text-box as...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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...
0
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,...

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.