473,503 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deselect a Group of Check Boxes

32 New Member
Good afternoon,

I would like to know if anyone can direct me as to how I can write a VBA code to deselect about 26 check boxes, for all records.

I have been searching the internet, but I haven't came across anything.

Right now I have a command button on the form, that is able to deselect one checkbox for a single record. I don't want to have to hard code in all the checkboxes names into VBA.

Thanks
Mar 7 '07 #1
18 2706
Rabbit
12,516 Recognized Expert Moderator MVP
Expand|Select|Wrap|Line Numbers
  1. Dim Ctl As Control
  2. For Each Ctl In Me.Controls
  3.    If Ctl.Properties("ControlType") = acCheckBox Then Ctl = False
  4. Next Ctl
  5.  
Mar 7 '07 #2
klove1209
32 New Member
Thank you so much. Now the only problem is that it work for 1 out of 22 records. For each row (record), there are about 22 check boxes, so in actuality, I need to clear about 400 check boxes.



Expand|Select|Wrap|Line Numbers
  1. Dim Ctl As Control
  2. For Each Ctl In Me.Controls
  3.    If Ctl.Properties("ControlType") = acCheckBox Then Ctl = False
  4. Next Ctl
  5.  
Mar 7 '07 #3
Rabbit
12,516 Recognized Expert Moderator MVP
For ease of implementation, put the code in the On Current event of the form. Change the form to continous form view. Then open the form. You can change it back after.
Mar 7 '07 #4
klove1209
32 New Member
Ok I did as you suggested. When the I switched it to form view, only the first row deselected. All the other rows remained the same.


For ease of implementation, put the code in the On Current event of the form. Change the form to continous form view. Then open the form. You can change it back after.
Mar 7 '07 #5
klove1209
32 New Member
I just tested using the move next record button, and once I did that, it deslected each row as it appeared. I guess I need to have a movenext function in there?



Ok I did as you suggested. When the I switched it to form view, only the first row deselected. All the other rows remained the same.
Mar 7 '07 #6
Rabbit
12,516 Recognized Expert Moderator MVP
Are you sure you set the Default View to Continous Form?
Mar 7 '07 #7
klove1209
32 New Member
it was already set to that.


Are you sure you set the Default View to Continous Form?
Mar 7 '07 #8
Rabbit
12,516 Recognized Expert Moderator MVP
Odd, it should work. I just tested it and it works. Not an exact replica of what you have but something similar.

Post your code along with the Event Statements.
Mar 7 '07 #9
klove1209
32 New Member
There aren't really any event statements. It just the deselect button that I am not using. All my records return true/false statements back to a table.

Here is the code:

Private Sub Form_Current()
Dim chk As CheckBox
Dim Ctl As Control

For Each Ctl In Me.Controls

If Ctl.Properties("ControlType") = acCheckBox Then Ctl = False

Next Ctl


End Sub







Odd, it should work. I just tested it and it works. Not an exact replica of what you have but something similar.

Post your code along with the Event Statements.
Mar 7 '07 #10
Rabbit
12,516 Recognized Expert Moderator MVP
Try this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3. Dim Ctl As Control
  4. Dim i As Integer
  5.  
  6. For i = 1 to Me.RecordSet.Count
  7.    For Each Ctl In Me.Controls
  8.       If Ctl.Properties("ControlType") = acCheckBox Then Ctl = False
  9.    Next Ctl
  10.    DoCmd.GoToRecord ,, acNext
  11.    i = i + 1
  12. Next i
  13.  
  14. End Sub
Mar 7 '07 #11
klove1209
32 New Member
I am getting an error with the .Count propert. It says the object doesn't support that property.

Try this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3. Dim Ctl As Control
  4. Dim i As Integer
  5.  
  6. For i = 1 to Me.RecordSet.Count
  7.    For Each Ctl In Me.Controls
  8.       If Ctl.Properties("ControlType") = acCheckBox Then Ctl = False
  9.    Next Ctl
  10.    DoCmd.GoToRecord ,, acNext
  11.    i = i + 1
  12. Next i
  13.  
  14. End Sub
Mar 7 '07 #12
Rabbit
12,516 Recognized Expert Moderator MVP
I am getting an error with the .Count propert. It says the object doesn't support that property.
Guess we'll have to use a clone:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3. Dim Ctl As Control
  4. Dim i As Integer
  5. Dim Rst As RecordSet
  6.  
  7. Set Rst = Me.RecordsetClone
  8. For i = 1 to Rst.Count
  9.    For Each Ctl In Me.Controls
  10.       If Ctl.Properties("ControlType") = acCheckBox Then Ctl = False
  11.    Next Ctl
  12.    DoCmd.GoToRecord ,, acNext
  13.    i = i + 1
  14. Next i
  15.  
  16. End Sub
Mar 7 '07 #13
klove1209
32 New Member
I got it working. Instead of using the recordset.count, I used Me.controls.count!

I am getting an error with the .Count propert. It says the object doesn't support that property.
Mar 7 '07 #14
klove1209
32 New Member
The only problem with this, it that it is moving next about 10 records instead of stopping at the last checkbox.

I got it working. Instead of using the recordset.count, I used Me.controls.count!
Mar 7 '07 #15
Rabbit
12,516 Recognized Expert Moderator MVP
The only problem with this, it that it is moving next about 10 records instead of stopping at the last checkbox.
Use the code from post 13 instead
Mar 7 '07 #16
klove1209
32 New Member
I tried using that also,
I got an error on the RecordsetClone.


Use the code from post 13 instead
Mar 7 '07 #17
Rabbit
12,516 Recognized Expert Moderator MVP
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3. Dim Ctl As Control
  4. Dim i As Integer
  5. Dim Rst As RecordSet
  6.  
  7. Set Rst = CurrentDb.OpenRecordset("[Table Name]")
  8. For i = 1 to Rst.Count
  9.    For Each Ctl In Me.Controls
  10.       If Ctl.Properties("ControlType") = acCheckBox Then Ctl = False
  11.    Next Ctl
  12.    DoCmd.GoToRecord ,, acNext
  13.    i = i + 1
  14. Next i
  15.  
  16. End Sub
Mar 8 '07 #18
Rabbit
12,516 Recognized Expert Moderator MVP
Ooops, my bad. I forgot it's not .Count, it's .RecordCount
Mar 8 '07 #19

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

Similar topics

6
3848
by: Orchid | last post by:
I have 2 fields with Radio button Data Type, and both fields with more than one options. On Field1, I want the user to select option1, then Field2 is shown and able to select. If the user selects...
4
10509
by: moondaddy | last post by:
There are different times when I will have a group of checkboxes and need to force only one to be checked at a time. I would also like to do this client side and not require a postback. These...
4
7128
by: GJP | last post by:
Hello. I have two list boxes. One with a picture name, and one for the ID of that picture (both coming from a database). The user selects the name of the picture and presses a button, the...
1
14436
by: Heck | last post by:
Hi everyone. I have created a simple table called "ReceptionTable" to input all materials coming to a drilling rig. I have included in this table a yes/no field (check box) that is selected from a...
2
2241
by: birwin | last post by:
I found a Javascript snippet that very effectively checks all boxes on a page, even on a page on which the input tags are in tables and on which I use a lot of other javascript. Unfortunately it is...
1
4571
by: Bailu | last post by:
Hi, I am a newbie in wxPython and doing a program with ListBox, I want to select and deselect items in this box, I have use self.devlist = wx.ListBox(self, style=wx.LB_MULTIPLE)...
5
7679
by: zacks | last post by:
I am having a strange issue with an application written in .NET 2.0. Actually it is in VB.NET but I think my problem is not language specific, but a .NET Framework issue. On a form I have a...
3
2326
by: student4lifer | last post by:
I thought the group check boxes would be parsed as an array, but the code below didn't print out as I expected. Could someone explain what I am missing? Thanks. ========== <html> <body>...
2
3383
beacon
by: beacon | last post by:
Hi everybody, I have a form that has a combo box that asks the user to select the program they work on. Once the user selects the program, a SQL statement populates the row source for 4 staff...
0
7084
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...
0
7278
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
7328
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...
1
6991
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
7458
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
4672
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...
0
3167
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...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.