REF calculations & check box replication

G

Guest

Two questions :

1) How do I replicate a check box answer like I would a formfield using REF?
For example, REF Text1 will display (replicate) the result from the
formfield Text1.. How do I replicate a check box so if one check box is
checked, then a second is also checked based on the first? REF Check1 does
not display anything.

2) Text1 + Text2 works for formfields becuase formfields have names such as
Text1 and Text2. What works for REF fields? How do I add two reference
fields. I do not see a name for REF fields, so I do not see how I can add
using Ref1 + Ref2 for example.
 
M

macropod

Hi ericm,

You can't use a REF field to replicate a checkbox formfield's result. You'd need to use vba to interrogate the checkbox state and do
whatever you want from that.

Neither can you add two REF fields. However, since your REF fields must be getting their values from somewhere, all you need to do
is to point your calculation to the same source.

Cheers
 
G

Guest

Regarding my first question : I'm familiar with Word, but not the Visual
Basic language (I assume VBA stands fro Visual Basic). At any rate, you're
talking about the language that macros use to run, right? Yeah, I'm not at
all familar with that. However, what you describe does not sound difficult.
It sounds like you're describing maybe a 3-line VBA subroutine that 1) checks
the current document's check box named 'checkbox1', for example, for it's
current state, which will either be TRUE or FALSE, ONE or ZERO, CHECKED or
UNCHECKED, etc.., then 2) based on the current state, either a
symbol-character of a box with an "X" in it will be displayed, or 3) a
symbol-character of a box without an "X" will be displayed.

Right?

Regarding my second question : Can I use a COUNT function in Word? Can I
use a CHOOSE function in Word? How many levels of IF can I use in Word? I
have an idea. Thanks.

- Eric

----------------------

macropod said:
Hi ericm,

You can't use a REF field to replicate a checkbox formfield's result. You'd need to use vba to interrogate the checkbox state and do
whatever you want from that.

Neither can you add two REF fields. However, since your REF fields must be getting their values from somewhere, all you need to do
is to point your calculation to the same source.

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------

ericm said:
Two questions :

1) How do I replicate a check box answer like I would a formfield using REF?
For example, REF Text1 will display (replicate) the result from the
formfield Text1.. How do I replicate a check box so if one check box is
checked, then a second is also checked based on the first? REF Check1 does
not display anything.

2) Text1 + Text2 works for formfields becuase formfields have names such as
Text1 and Text2. What works for REF fields? How do I add two reference
fields. I do not see a name for REF fields, so I do not see how I can add
using Ref1 + Ref2 for example.
 
M

macropod

Hi Eric,

If you want one checkbox to be set according to the value of another, you'd need to set the first checkbox to run a macro on exit.
For example, say you have two checkboxes, with bookmark names 'Check1' and 'Check2'. If you set the properties of the checkbox named
'Check1' to run a macro named 'SetChk2' on exit, then the following macro will set the checkbox named 'Check2' to the same state:

Sub SetChk2()
ActiveDocument.FormFields("Check2").CheckBox.Value = ActiveDocument.FormFields("Check1").CheckBox.Value
End Sub

To set the checkbox named 'Check2' to the opposite state, simply insert the word 'Not' after the '='.

If you want to make the state of the checkbox named 'Check1' available to other fields in the document (eg a REF field),
considerably more code is needed, but at least the following routine can be called by all checkboxes that you you might want to use
it with:

Sub SetCheckState()
Dim ChkMrk As String
ChkMrk = Selection.Range.Bookmarks(1).Name
SetProp ChkMrk, ThisDocument.FormFields(ChkMrk).Result, msoPropertyTypeString
End Sub

Sub SetCustomPropertyName()
' see: http://support.microsoft.com/kb/212618/en-us
' **************************************************
' This SubRoutine passes the Custom Property Name,
' Value, and Property Type to the SetProp subroutine.
' **************************************************
' Set the custom property "MyCustomPropertyName" equal ' to "MyCustomValue".
' The msoPropertyTypeString constant specifies the type of property, and must be included.
SetProp "MyCustomPropertyName", "MyCustomValue", _
msoPropertyTypeString
End Sub

Sub SetProp(CDPName As String, CDPValue As Variant, Optional CDPType As Long)
' ***********************************************
' The SetProp routine checks to see if the Custom Document Property pre-exists. If it exists,
' it adds the new value. If it does not exist, it creates the new property and adds the new value.
' ***********************************************
' Make sure the optional argument CDPType is set. If it is missing, make it a string value.
Dim oCDP, oProp, msg
If IsMissing(CDPType) Then
CDPType = msoPropertyTypeString
End If
Set oCDP = ActiveDocument.CustomDocumentProperties
' Compare each custom document property to the property you want to create to see if it exists.
For Each oProp In oCDP
' If the Custom Property exists...
If oProp.Name = CDPName Then
With oProp
' ...the custom property Type you are setting must match the pre-existing custom property.
If .Type <> CDPType Then
msg = "The custom property types do not match."
msg = msg + " Custom property not set."
MsgBox msg
' End the routine.
Exit Sub
End If
.LinkToContent = False
' Set the new value.
.Value = CDPValue
End With
' A match was found, so exit the routine.
Exit Sub
End If
Next oProp
' No match was found. Create a new property and value.
oCDP.Add Name:=CDPName, Value:=CDPValue, Type:=CDPType, LinkToContent:=False
End Sub

Then, to work with the checkbox state in other field, you can now get at it via a DOCPROPERTY field, coded as:{DOCPROPERTY "Check1"}

Word does have a COUNT field, which is mainly intended for use in tables, but it doesn't have a CHOOSE field. You can nest up to 20
IF fields. If your idea is based on evaluating field contents, check out my Word Field Maths 'tutorial', at:
http://www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=365442
or
http://www.gmayor.com/downloads.htm#Third_party
The tutorial shows how you can evaluate text strings, as well as numbers.

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------

ericm said:
Regarding my first question : I'm familiar with Word, but not the Visual
Basic language (I assume VBA stands fro Visual Basic). At any rate, you're
talking about the language that macros use to run, right? Yeah, I'm not at
all familar with that. However, what you describe does not sound difficult.
It sounds like you're describing maybe a 3-line VBA subroutine that 1) checks
the current document's check box named 'checkbox1', for example, for it's
current state, which will either be TRUE or FALSE, ONE or ZERO, CHECKED or
UNCHECKED, etc.., then 2) based on the current state, either a
symbol-character of a box with an "X" in it will be displayed, or 3) a
symbol-character of a box without an "X" will be displayed.

Right?

Regarding my second question : Can I use a COUNT function in Word? Can I
use a CHOOSE function in Word? How many levels of IF can I use in Word? I
have an idea. Thanks.

- Eric

----------------------

macropod said:
Hi ericm,

You can't use a REF field to replicate a checkbox formfield's result. You'd need to use vba to interrogate the checkbox state and
do
whatever you want from that.

Neither can you add two REF fields. However, since your REF fields must be getting their values from somewhere, all you need to
do
is to point your calculation to the same source.

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------

ericm said:
Two questions :

1) How do I replicate a check box answer like I would a formfield using REF?
For example, REF Text1 will display (replicate) the result from the
formfield Text1.. How do I replicate a check box so if one check box is
checked, then a second is also checked based on the first? REF Check1 does
not display anything.

2) Text1 + Text2 works for formfields becuase formfields have names such as
Text1 and Text2. What works for REF fields? How do I add two reference
fields. I do not see a name for REF fields, so I do not see how I can add
using Ref1 + Ref2 for example.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top