Group:  Microsoft Word ยป microsoft.public.word.docmanagement
Thread: Auto Fields

Geek News

Auto Fields
Eric 12/29/2008 10:03:01 PM
I have a form that I have setup with different check boxes. I was wondering
if I could setup a formula that would auto insert a number (an account) into
a field on the bottom of the page depending on the box that is checked? I am
thinking that an "if" statement might be able to do this, but I am not sure
how to make this work. Can someone help me with this? Is this even possible
to do?

Thanks
Re: Auto Fields
"Graham Mayor" <gmayor[ at ]REMOVETHISmvps.org> 12/30/2008 9:46:30 AM
You cannot create a formula from a check box, but it is easy enough with vba
to evaluate the result of a check box and insert stuff at various locations
based on that result - there are assorted examples at
http://www.gmayor.com/SelectFile.htm and
http://www.gmayor.com/word_vba_examples.htm
If you need more help then you will have to explain what you require in
greater depth, in relation to the check boxes and how they relate to the
number (from where?) that you want to insert.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Eric wrote:
[Quoted Text]
> I have a form that I have setup with different check boxes. I was
> wondering if I could setup a formula that would auto insert a number
> (an account) into a field on the bottom of the page depending on the
> box that is checked? I am thinking that an "if" statement might be
> able to do this, but I am not sure how to make this work. Can
> someone help me with this? Is this even possible to do?
>
> Thanks


Re: Auto Fields
Eric 12/30/2008 11:02:09 PM
Thanks Graham, let me attempt to give you a simplistic example of what I'd
lke to do...

I'd like to create a form that has three options on top with check boxes,
let's say Red, Blue & Green. I want to associate an account number to each
color (Red-0001, Blue-0002 & Green-0003). I want the account number to
appear in a field further down on the form.

Red [] Blue [X] Green []
Account: 0002

Is this possible?

Let me know if you need additional description.

Thanks in advanced!


"Graham Mayor" wrote:

[Quoted Text]
> You cannot create a formula from a check box, but it is easy enough with vba
> to evaluate the result of a check box and insert stuff at various locations
> based on that result - there are assorted examples at
> http://www.gmayor.com/SelectFile.htm and
> http://www.gmayor.com/word_vba_examples.htm
> If you need more help then you will have to explain what you require in
> greater depth, in relation to the check boxes and how they relate to the
> number (from where?) that you want to insert.
>
> --
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor - Word MVP
>
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>
>
> Eric wrote:
> > I have a form that I have setup with different check boxes. I was
> > wondering if I could setup a formula that would auto insert a number
> > (an account) into a field on the bottom of the page depending on the
> > box that is checked? I am thinking that an "if" statement might be
> > able to do this, but I am not sure how to make this work. Can
> > someone help me with this? Is this even possible to do?
> >
> > Thanks
>
>
>
Re: Auto Fields
"Graham Mayor" <gmayor[ at ]REMOVETHISmvps.org> 12/31/2008 7:41:13 AM
See http://word.mvps.org/faqs/tblsfldsfms/ExclusiveFmFldChbxs.htm for the
principles involved in making check boxes exclusive, though personally I
would put the check boxes in a borderless table cell rather than in a frame
and change the code to that as follows.
The macro works on the premise that you have three check boxes named Red,
Blue and Green and a Text form field named Text1 which displays the result
text.

If you prefer to use the frame then change the line

For Each oField In Selection.Tables(1).Range.FormFields
to
For Each oField In Selection.Frames(1).Range.FormFields


Sub MakeCheckBoxesExclusive()
Dim oField As FormField
For Each oField In Selection.Tables(1).Range.FormFields
oField.CheckBox.Value = False
Next oField
Selection.FormFields(1).CheckBox.Value = True
If ActiveDocument.FormFields("Red").CheckBox.Value = True Then
ActiveDocument.FormFields("Text1").Result = "Account: 0001"
End If
If ActiveDocument.FormFields("Blue").CheckBox.Value = True Then
ActiveDocument.FormFields("Text1").Result = "Account: 0002"
End If
If ActiveDocument.FormFields("Green").CheckBox.Value = True Then
ActiveDocument.FormFields("Text1").Result = "Account: 0003"
End If
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Eric wrote:
[Quoted Text]
> Thanks Graham, let me attempt to give you a simplistic example of
> what I'd lke to do...
>
> I'd like to create a form that has three options on top with check
> boxes, let's say Red, Blue & Green. I want to associate an account
> number to each color (Red-0001, Blue-0002 & Green-0003). I want the
> account number to appear in a field further down on the form.
>
> Red [] Blue [X] Green []
> Account: 0002
>
> Is this possible?
>
> Let me know if you need additional description.
>
> Thanks in advanced!
>
>
> "Graham Mayor" wrote:
>
>> You cannot create a formula from a check box, but it is easy enough
>> with vba to evaluate the result of a check box and insert stuff at
>> various locations based on that result - there are assorted examples
>> at http://www.gmayor.com/SelectFile.htm and
>> http://www.gmayor.com/word_vba_examples.htm
>> If you need more help then you will have to explain what you require
>> in greater depth, in relation to the check boxes and how they relate
>> to the number (from where?) that you want to insert.
>>
>> --
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>> Graham Mayor - Word MVP
>>
>> My web site www.gmayor.com
>> Word MVP web site http://word.mvps.org
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>
>>
>> Eric wrote:
>>> I have a form that I have setup with different check boxes. I was
>>> wondering if I could setup a formula that would auto insert a number
>>> (an account) into a field on the bottom of the page depending on the
>>> box that is checked? I am thinking that an "if" statement might be
>>> able to do this, but I am not sure how to make this work. Can
>>> someone help me with this? Is this even possible to do?
>>>
>>> Thanks


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net