I have a list of states on a form, in which the user can click on various states that are applicable to the form. There is a "ALL State" option (CheckBoxALL) in which if selected all of the state checkboxes will be checked. Below is the following code:
Private Sub CheckBoxALL_Click()
If CheckBoxAll = True Then
CheckBoxState01 = True
CheckBoxState02 = True
CheckBoxState03 = True
CheckBoxState04 = True
etc.....
CheckBoxState52 = True
Else
CheckBoxState01 = False
CheckBoxState02 = False
CheckBoxState03 = False
CheckBoxState04 = False
CheckBoxState05 = False
CheckBoxState06 = False
etc.........CheckBoxState52 = False
End If
End Sub
_______________________
My question is if there is a cleaner way to write this code than the way I wrote it since I am still in VBA learning mode?
I tried something like this but it keeps error out:
Private Sub CheckBoxALL_Click()
Dim CheckALL As Boolean
Set CheckALL = ActiveDocument.FormFields("CheckBoxALL").CheckBox. Value
If CheckALL("CheckBoxALL").CheckBox.Value = True Then
For i = 1 To 52
CheckALL("CheckBoxState0" & i).CheckBox.Value = True
Next i
Else
For i = 1 To 52
CheckALL("CheckBoxState0" & i).CheckBox.Value = False
Next i
End If
End Sub
_________________
My result so far has been compile errors and coding that does not work. Does anybody have any ideas??
Thanks,
Keith.
13 3374
Hi, Keith.
You may use the following code. -
For i = 1 To 52
-
Me.Controls("CheckBox" & Format(i, "00")).Value = True
-
Next i
-
Just out of curiosity. Does that mean you have a table with 52 Yes/No fields?
Regards,
Fish
- Private Sub CheckBoxAll_AfterUpdate()
-
-
Dim ctl As Control
-
-
If Me.CheckBoxAll = -1 Then
-
-
For Each ctl In Me.Controls
-
-
If ctl.ControlType = acCheckBox Then
-
-
ctl = -1
-
-
End If
-
Next
-
-
Else
-
-
If Me.CheckBoxAll = -1 Then
-
-
For Each ctl In Me.Controls
-
-
If ctl.ControlType = acCheckBox Then
-
-
ctl = 0
-
-
End If
-
Next
-
End If
-
End Sub
Linq ;0)>
Even better, Fish, when the controls are sequentially named! But the checkbox names are "CheckBoxState" & i so - Me.Controls("CheckBoxState" & Format(i, "00")).Value = True
Linq ;0)>
Even better, Fish, when the controls are sequentially named! But the checkbox names are "CheckBoxState" & i so - Me.Controls("CheckBoxState" & Format(i, "00")).Value = True
Linq ;0)> -
Private Sub CheckBoxAll_AfterUpdate()
-
-
Dim ctl As Control
-
-
With Me
-
For Each ctl In .Controls
-
If ctl.ControlType = acCheckBox Then ctl = .CheckBoxAll
-
Next
-
End With
-
-
Set ctl = Nothing
-
-
End Sub
-
Eye for eye, Linq. LOL.
Best regards,
Fish
Thanks for all the input... I just go back out of a meeting....
This is a form with a section in it for people to pick (CheckBoxes) the applicable state(s). I failed to mention that it was a form created out of Word 2003. That seems to make a difference because it does not recognize the command "Controls" (VBA error message:"Method or data member not found"). Does that mean that it can not be done if this form was created in Word or I would have to use some other command.....
Thanks,
Keith.
Ok, Keith.
Try the following code. -
Private Sub CheckBoxAll_Click()
-
-
Dim fldField As Field
-
-
For Each fldField In ThisDocument.Fields
-
If TypeName(fldField.OLEFormat.Object) = "CheckBox" Then _
-
fldField.OLEFormat.Object.Value = ThisDocument.CheckBoxAll
-
Next
-
-
Set fldField = Nothing
-
-
End Sub
-
Hello:
I tried that and got the following error:
Run time 91 "Object Variable or with Block Variable not Set"
I don't really understand what the code is doing to interpret the error message. Any ideas?
Thanks,
Keith
Well. You may send me it via email. I will PM you my email address.
Well. You may send me it via email. I will PM you my email address.
Fish did you get it?? I sent it to you yesterday.
Thank,
Keith.
Fish did you get it?? I sent it to you yesterday.
Thank,
Keith.
Hello, Keith.
Sorry for delay. I've send you a working copy of your file. The problem wasn't in coding but in the file itself - it was stucked in design mode in a hopeless try to create a control. So I've just copied the table to an empty word document and added the code posted above. Looks like it is working.
Regards,
Fish
Thanks Fish for all your help. I thought something fishy was going on no pun intended.
Thanks again :-)
Keith.
I have a list of states on a form, in which the user can click on various states that are applicable to the form. There is a "ALL State" option (CheckBoxALL) in which if selected all of the state checkboxes will be checked. Below is the following code:
Private Sub CheckBoxALL_Click()
If CheckBoxAll = True Then
CheckBoxState01 = True
CheckBoxState02 = True
CheckBoxState03 = True
CheckBoxState04 = True
etc.....
CheckBoxState52 = True
Else
CheckBoxState01 = False
CheckBoxState02 = False
CheckBoxState03 = False
CheckBoxState04 = False
CheckBoxState05 = False
CheckBoxState06 = False
etc.........CheckBoxState52 = False
End If
End Sub
_______________________
My question is if there is a cleaner way to write this code than the way I wrote it since I am still in VBA learning mode?
I tried something like this but it keeps error out:
Private Sub CheckBoxALL_Click()
Dim CheckALL As Boolean
Set CheckALL = ActiveDocument.FormFields("CheckBoxALL").CheckBox. Value
If CheckALL("CheckBoxALL").CheckBox.Value = True Then
For i = 1 To 52
CheckALL("CheckBoxState0" & i).CheckBox.Value = True
Next i
Else
For i = 1 To 52
CheckALL("CheckBoxState0" & i).CheckBox.Value = False
Next i
End If
End Sub
_________________
My result so far has been compile errors and coding that does not work. Does anybody have any ideas??
Thanks,
Keith.
Hi Keith! Can I ask you something please?
Is the first code you suggested right??
Because I have only 5 checkboxes and it seems easyer to use it...
Thanks
maria
Yes, Maria! This will work fine: - Private Sub CheckBoxALL_Click()
-
-
If CheckBoxAll = True Then
-
-
CheckBox1 = True
-
CheckBox2 = True
-
CheckBox3 = True
-
CheckBox4 = True
-
CheckBox5 = True
-
-
Else
-
-
CheckBox1 = False
-
CheckBox2 = False
-
CheckBox3 = False
-
CheckBox4 = False
-
CheckBox5 = False
-
-
End If
-
-
End Sub
-
You just wouldn't want to have to do all this for 50+ checkboxes!
Welcome to TheScripts!
Linq ;0)> Sign in to post your reply or Sign up for a free account.
Similar topics
by: Adrian Parker |
last post by:
I have a PHP generated page which displays X many records. Each record has
a checkbox preceding it. The user checks several checkboxes, and hits a
delete button. All the corresponding records...
|
by: Mohammed Mazid |
last post by:
Hi folks!
Can anyone please help me with this?
I am developing a Quiz program but I am stuck with "multiple answers".
Basically I need some sort of code that would select multiple answers...
|
by: Edward |
last post by:
The following html / javascript code produces a simple form with check
boxes. There is also a checkbox that 'checks all' form checkboxes
hotmail style:
<html>
<head>
<title></title>
</head>...
|
by: terence.parker |
last post by:
I currently have the following JS in my header:
function checkall(thestate) {
var checkboxes=eval("document.forms.EssayList.file_id")
for (i=0;i<checkboxes.length;i++)...
|
by: jamesboulter |
last post by:
Dear all,
I can find plenty of functions that check all checkboxes with a certain
HTML "name" attribute, but on the page in question, each is named
slightly differently:
Therapy_1
Therapy_2...
|
by: Mike Fellows |
last post by:
I have created some checkboxes within a panel using the code below
Dim NewCheckbox As New CheckBox
Me.Panel2.Controls.Add(NewCheckbox)
NewCheckbox.Location = New Point(XLocation, YLocation)...
|
by: rn5a |
last post by:
All the rows in a DataGrid, including the Header, are accompanied with
a CheckBox. I want that when the CheckBox in the Header is checked,
then all the CheckBoxes should automatically get checked....
|
by: PhpCool |
last post by:
Hi, since sometime I'm stuck in a problem where I want to check or
uncheck all the checkboxes. If I'm choosing name for the checkbox
array as 'chkbx_ary' then I'm able to check/uncheck all the...
|
by: Anuj |
last post by:
Hi, since sometime I'm stuck in a problem where I want to check or
uncheck all the checkboxes. If I'm choosing name for the checkbox
array as 'chkbx_ary' then I'm able to check/uncheck all the...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
| |