Auto populate drop down boxes when clicking a check box

February 24th, 2009 - 12:38 pm ET by dmars | Report spam
Hi,

I am creating a form in Word. I have a check box, "required for all".
There are multiple training roles with drop down boxes with 2 choices
"required" or "not required". If the check box is selected then all of the
drop down boxes should auto populate with the word "required".

I am new at this and could really use your help.

Thanks
email Follow the discussionReplies 10 repliesReplies Make a reply

Similar topics

Replies

#1 Greg Maxey
February 24th, 2009 - 01:06 pm ET | Report spam
dmars,

Something like this. Name the checkbox "CheckAll." Name the dropdowns
DDReq1, DDReq2, DDReq3, etc. The first entry in the dropdowns is "Required"
the second entry is "Not Required" Run this macro on exit from the
checkbox.


Sub CBOnExit()
Dim oFFs As FormFields
Dim oFF As FormField
Dim i As Long
Set oFFs = ActiveDocument.FormFields
If oFFs("CheckALL").CheckBox.Value = True Then
i = 1
Else
i = 2
End If
For Each oFF In oFFs
If oFF.Type = wdFieldFormDropDown Then
If InStr(oFF.Name, "DDReq") > 0 Then
oFF.DropDown.Value = i
End If
End If
Next


End Sub

dmars wrote:
Hi,

I am creating a form in Word. I have a check box, "required for all".
There are multiple training roles with drop down boxes with 2 choices
"required" or "not required". If the check box is selected then all
of the drop down boxes should auto populate with the word "required".

I am new at this and could really use your help.

Thanks



Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org
Replies Reply to this message
#2 dmars
February 24th, 2009 - 01:31 pm ET | Report spam
Thank yo so very much! it is almost working. When I check the box nothing
happens. If I tab to the check box and tab past it the fields populate
correctly without clicking in the box. It doesn't seem to be working when I
actually click in the box and select it. The first entry in the drop down
boxes is a blank line. would this have any affect on the macro?

Thanks

"Greg Maxey" wrote:

dmars,

Something like this. Name the checkbox "CheckAll." Name the dropdowns
DDReq1, DDReq2, DDReq3, etc. The first entry in the dropdowns is "Required"
the second entry is "Not Required" Run this macro on exit from the
checkbox.


Sub CBOnExit()
Dim oFFs As FormFields
Dim oFF As FormField
Dim i As Long
Set oFFs = ActiveDocument.FormFields
If oFFs("CheckALL").CheckBox.Value = True Then
i = 1
Else
i = 2
End If
For Each oFF In oFFs
If oFF.Type = wdFieldFormDropDown Then
If InStr(oFF.Name, "DDReq") > 0 Then
oFF.DropDown.Value = i
End If
End If
Next


End Sub

dmars wrote:
> Hi,
>
> I am creating a form in Word. I have a check box, "required for all".
> There are multiple training roles with drop down boxes with 2 choices
> "required" or "not required". If the check box is selected then all
> of the drop down boxes should auto populate with the word "required".
>
> I am new at this and could really use your help.
>
> Thanks

Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org






Replies Reply to this message
#3 Greg Maxey
February 24th, 2009 - 01:42 pm ET | Report spam
dmars,

Unfortunately there is no way to detect the actual event (i.e., checking or
unchecking the box). You can check or uncheck the box and nothing happens
until a detectable event occurs (e.g., exiting the checkbox). That is just
the way it is and AFAIK there is no way around it.

Yes having a "blanks" as the first option will have and effect. In that
case the the availble dropdown.values are 1, 2, or 3.

1 = Blank
2 = Required
3 = Not Required

If the dropdowns appear blank originally then you might want return them to
blank if the box is check and then unchecked or you might want to have them
populate with "Not Required"

dmars wrote:
Thank yo so very much! it is almost working. When I check the box
nothing happens. If I tab to the check box and tab past it the
fields populate correctly without clicking in the box. It doesn't
seem to be working when I actually click in the box and select it.
The first entry in the drop down boxes is a blank line. would this
have any affect on the macro?

Thanks

"Greg Maxey" wrote:

dmars,

Something like this. Name the checkbox "CheckAll." Name the
dropdowns DDReq1, DDReq2, DDReq3, etc. The first entry in the
dropdowns is "Required" the second entry is "Not Required" Run this
macro on exit from the checkbox.


Sub CBOnExit()
Dim oFFs As FormFields
Dim oFF As FormField
Dim i As Long
Set oFFs = ActiveDocument.FormFields
If oFFs("CheckALL").CheckBox.Value = True Then
i = 1
Else
i = 2
End If
For Each oFF In oFFs
If oFF.Type = wdFieldFormDropDown Then
If InStr(oFF.Name, "DDReq") > 0 Then
oFF.DropDown.Value = i
End If
End If
Next


End Sub

dmars wrote:
Hi,

I am creating a form in Word. I have a check box, "required for
all". There are multiple training roles with drop down boxes with 2
choices "required" or "not required". If the check box is selected
then all of the drop down boxes should auto populate with the word
"required".

I am new at this and could really use your help.

Thanks



Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org





Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org
Replies Reply to this message
#4 dmars
February 24th, 2009 - 02:54 pm ET | Report spam
THANKS! I AM WORKING MY WAY THORUGH THIS. i DID MODIFY YOUR CODE TO INCLUDE
3 OPTIONS. i EVEN FIGURED IT OUT ON MY OWN. HOW ABOUT THAT?
HERE IS THE WAY THAT I UPDATED THE CODE:

Sub CBOnExit()
Dim oFFs As FormFields
Dim oFF As FormField
Dim i As Long
Set oFFs = ActiveDocument.FormFields
If oFFs("CheckALL").CheckBox.Value = True Then
i = 2
Else
i = 3
End If
If oFFs("CheckALL").CheckBox.Value = False Then
i = 1
Else
i = 2
End If

For Each oFF In oFFs
If oFF.Type = wdFieldFormDropDown Then
If InStr(oFF.Name, "DDReq") > 0 Then
oFF.DropDown.Value = i
End If
End If
Next


End Sub

CAN YOU TELL ME IF IT WOULD BE DIFFICULT TO CREATE A CHECK BOX THAT WOULD
CLEAR ALL FIELDS? I AM AFRAID THE USER WILL CHECK THE BOX ACCIDENTALLY AND I
WOULD LIKE TO GIVE THEM AN OPTION TO CLEAR THE FORM.

THANKS AGAIN. I REALLY APPRECIATE YOUR HELP. I HAVE USED THE SERVICES OF
THIS FORUM A FEW TIMES AND FIND IT PRICELESS.

"Greg Maxey" wrote:

dmars,

Unfortunately there is no way to detect the actual event (i.e., checking or
unchecking the box). You can check or uncheck the box and nothing happens
until a detectable event occurs (e.g., exiting the checkbox). That is just
the way it is and AFAIK there is no way around it.

Yes having a "blanks" as the first option will have and effect. In that
case the the availble dropdown.values are 1, 2, or 3.

1 = Blank
2 = Required
3 = Not Required

If the dropdowns appear blank originally then you might want return them to
blank if the box is check and then unchecked or you might want to have them
populate with "Not Required"

dmars wrote:
> Thank yo so very much! it is almost working. When I check the box
> nothing happens. If I tab to the check box and tab past it the
> fields populate correctly without clicking in the box. It doesn't
> seem to be working when I actually click in the box and select it.
> The first entry in the drop down boxes is a blank line. would this
> have any affect on the macro?
>
> Thanks
>
> "Greg Maxey" wrote:
>
>> dmars,
>>
>> Something like this. Name the checkbox "CheckAll." Name the
>> dropdowns DDReq1, DDReq2, DDReq3, etc. The first entry in the
>> dropdowns is "Required" the second entry is "Not Required" Run this
>> macro on exit from the checkbox.
>>
>>
>> Sub CBOnExit()
>> Dim oFFs As FormFields
>> Dim oFF As FormField
>> Dim i As Long
>> Set oFFs = ActiveDocument.FormFields
>> If oFFs("CheckALL").CheckBox.Value = True Then
>> i = 1
>> Else
>> i = 2
>> End If
>> For Each oFF In oFFs
>> If oFF.Type = wdFieldFormDropDown Then
>> If InStr(oFF.Name, "DDReq") > 0 Then
>> oFF.DropDown.Value = i
>> End If
>> End If
>> Next
>>
>>
>> End Sub
>>
>> dmars wrote:
>>> Hi,
>>>
>>> I am creating a form in Word. I have a check box, "required for
>>> all". There are multiple training roles with drop down boxes with 2
>>> choices "required" or "not required". If the check box is selected
>>> then all of the drop down boxes should auto populate with the word
>>> "required".
>>>
>>> I am new at this and could really use your help.
>>>
>>> Thanks
>>
>> Greg Maxey - Word MVP
>>
>> My web site http://gregmaxey.mvps.org
>> Word MVP web site http://word.mvps.org

Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org






Replies Reply to this message
#5 Greg Maxey
February 24th, 2009 - 03:14 pm ET | Report spam
dmars,

Fix the CAPSLOCKS your post is hard to read (and some say it is the
equivelent of shouting).

Let's look at your code a little closer:

If oFFs("CheckALL").CheckBox.Value = True Then 'This line evaluates the
state of the checkbox
i = 2 'If it is true then i =2
Else
i = 3 'If it isn't true (then it is false) i = 3
End If

You have already evaluated the state of the checkbox so the following code
is redundant and can actually undo something done above

If oFFs("CheckALL").CheckBox.Value = False Then
i = i
Else
i = 2
End If


If these are your Dropdown values"

1 Blank space
2 Required
3 Not Required

Your first If ... End If statement will set the dropdown values to
"Required" if the checkbox is checked when the OnExit event fires and "Not
Required" if the checkbox isn't checked.

Your second If ... End If statement will set the dropdown values to "
" if the checkbox is not checked when the OnExit event fires and "Required"
if the checkbox is checked.

You need to decide which you want and use a single If ... End If statement
accordingly.

When you say clear "all" fields do you mean all of the DDReq fields or
literally "all" fields?

If the former then you should be able to use this as your single If End
If statement.

If oFFs("CheckALL").CheckBox.Value = False Then
i = i
Else
i = 2
End If



dmars wrote:
THANKS! I AM WORKING MY WAY THORUGH THIS. i DID MODIFY YOUR CODE TO
INCLUDE 3 OPTIONS. i EVEN FIGURED IT OUT ON MY OWN. HOW ABOUT THAT?
HERE IS THE WAY THAT I UPDATED THE CODE:

Sub CBOnExit()
Dim oFFs As FormFields
Dim oFF As FormField
Dim i As Long
Set oFFs = ActiveDocument.FormFields
If oFFs("CheckALL").CheckBox.Value = True Then
i = 2
Else
i = 3
End If
If oFFs("CheckALL").CheckBox.Value = False Then
i = 1
Else
i = 2
End If

For Each oFF In oFFs
If oFF.Type = wdFieldFormDropDown Then
If InStr(oFF.Name, "DDReq") > 0 Then
oFF.DropDown.Value = i
End If
End If
Next


End Sub

CAN YOU TELL ME IF IT WOULD BE DIFFICULT TO CREATE A CHECK BOX THAT
WOULD CLEAR ALL FIELDS? I AM AFRAID THE USER WILL CHECK THE BOX
ACCIDENTALLY AND I WOULD LIKE TO GIVE THEM AN OPTION TO CLEAR THE
FORM.

THANKS AGAIN. I REALLY APPRECIATE YOUR HELP. I HAVE USED THE
SERVICES OF THIS FORUM A FEW TIMES AND FIND IT PRICELESS.

"Greg Maxey" wrote:

dmars,

Unfortunately there is no way to detect the actual event (i.e.,
checking or unchecking the box). You can check or uncheck the box
and nothing happens until a detectable event occurs (e.g., exiting
the checkbox). That is just the way it is and AFAIK there is no way
around it.

Yes having a "blanks" as the first option will have and effect. In
that case the the availble dropdown.values are 1, 2, or 3.

1 = Blank
2 = Required
3 = Not Required

If the dropdowns appear blank originally then you might want return
them to blank if the box is check and then unchecked or you might
want to have them populate with "Not Required"

dmars wrote:
Thank yo so very much! it is almost working. When I check the box
nothing happens. If I tab to the check box and tab past it the
fields populate correctly without clicking in the box. It doesn't
seem to be working when I actually click in the box and select it.
The first entry in the drop down boxes is a blank line. would this
have any affect on the macro?

Thanks

"Greg Maxey" wrote:

dmars,

Something like this. Name the checkbox "CheckAll." Name the
dropdowns DDReq1, DDReq2, DDReq3, etc. The first entry in the
dropdowns is "Required" the second entry is "Not Required" Run
this macro on exit from the checkbox.


Sub CBOnExit()
Dim oFFs As FormFields
Dim oFF As FormField
Dim i As Long
Set oFFs = ActiveDocument.FormFields
If oFFs("CheckALL").CheckBox.Value = True Then
i = 1
Else
i = 2
End If
For Each oFF In oFFs
If oFF.Type = wdFieldFormDropDown Then
If InStr(oFF.Name, "DDReq") > 0 Then
oFF.DropDown.Value = i
End If
End If
Next


End Sub

dmars wrote:
Hi,

I am creating a form in Word. I have a check box, "required for
all". There are multiple training roles with drop down boxes with
2 choices "required" or "not required". If the check box is
selected then all of the drop down boxes should auto populate
with the word "required".

I am new at this and could really use your help.

Thanks



Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org





Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org





Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org
Replies Reply to this message
Help Create a new topicNext page Replies Make a reply
Search Make your own search