Check-box form field value in calculations

A

alex1st

I am trying to make a calculation formula which uses one of the check-box
fields in the form (without writing VBA code). What I can't figure out is the
value of the check-box field. It seems that it is always 0, no matter whether
the check-box is ON or OFF.

What is the value of such field?

TIA
 
G

Graham Mayor

You cannot do that without vba eg

If ActiveDocument.FormFields("Check1").CheckBox.Value = True Then
ActiveDocument.Variables("sCheck1").Value = 1
Else
ActiveDocument.Variables("sCheck1").Value = 0
End If

You could then use the docvariable sCheck1 in a calculation


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

alex1st

Thanks Graham for quick reply. This is unfortunate - maybe a good wish-list
point for the Word product management.

The tip on ActiveDocument.Variables is a good one, though. I used a
on-screen field for the intermediate result for now.

Is there any reference on "Calculation" field equation options?
 
P

Pesach Shelnitz

Hi,

The value of a checkbox is a Boolean. The numerical value of a VB Boolean is
-1 when it is True or 0 when it is False. You should see a value of -1 when
the checkbox is selected (ON), and the value should be equal to 0 only when
the checkbox is cleared (OFF).
 
A

alex1st

I tried the tip on ActiveDocument.Variables, but couldn't make it to work.

I made a field named "ShowFactor" that has "=1+GradeFactor" in calculation
formula. In the macro I added the following statements:

If ActiveDocument.FormFields("GameEasy").CheckBox.Value = True Then
ActiveDocument.Variables("GradeFactor").Value = 0
End If

If ActiveDocument.FormFields("GameMid").CheckBox.Value = True Then
ActiveDocument.Variables("GradeFactor").Value = 0.025
End If

If ActiveDocument.FormFields("GameDfcl").CheckBox.Value = True Then
ActiveDocument.Variables("GradeFactor").Value = 0.05
End If

Alas, the "ShowFactor" field shows only "1". What am I doing wrong?
 
G

Graham Mayor

The form field ShowFactor does not understand the docvariable. You could use
a simple Word field
{ = 1 + { DOCVariable GradeFactor } }
or
you could instead write the result to a form field eg

If ActiveDocument.FormFields("GameEasy").CheckBox.Value = True Then
ActiveDocument.FormFields("GradeFactor").Result = 0
End If

If ActiveDocument.FormFields("GameMid").CheckBox.Value = True Then
ActiveDocument.FormFields("GradeFactor").Result = 0.025
End If

If ActiveDocument.FormFields("GameDfcl").CheckBox.Value = True Then
ActiveDocument.FormFields("GradeFactor").Result = 0.05
End If

run the macro on entry to the field Grade Factor
You may find - http://word.mvps.org/FAQs/TblsFldsFms/ExclusiveFmFldChbxs.htm
and
http://www.gmayor.com/SelectFile.htm useful.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

alex1st

Graham,

10x. I'll try DOCVariable. The FormFields is what I alrady use in the VBA
code. It works well, but requires a field on the screen.

Regarding the example: All my fields are in the table (and there are a
couple of dozens of them), so I used a different approach - using exit macro
and setting the rest of the check-boxes to OFF, as follows:

If ActiveDocument.FormFields("GameEasy").CheckBox.Value = True Then
ActiveDocument.FormFields("GameMid").CheckBox.Value = False
ActiveDocument.FormFields("GameDfcl").CheckBox.Value = False
End If
 

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