It works but can someone explain why the others don't?

D

Dale

I have tried the following code three different ways as shown below,
but only one worked, the other two displayed nothing on the word doc.
If someone can explain why that would be great. I am learning VBA and
would like to understand the reasons.

1st Example that didn't display anything on the doc:

Dim strX as String
strX = "X"

If chkFiling.Value = Checked Then
ActiveDocument.FormFields("bkFiling").Result = strX
End If
If chkReflect.Value = Checked Then
ActiveDocument.FormFields("bkReflect").Result = strX
End If
More code . . .



2nd Example that didn't display anything on the doc:

Dim strX as String
strX = "X"

If chkFiling.Value = 1 Then
ActiveDocument.FormFields("bkFiling").Result = strX
End If
If chkReflect.Value = 1 Then
ActiveDocument.FormFields("bkReflect").Result = strX
End If
More code . . .

3rd Example that DOES display something on the doc:

Dim strX as String
strX = "X"

If chkFiling.Value = True Then
ActiveDocument.FormFields("bkFiling").Result = strX
End If
If chkReflect.Value = True Then
ActiveDocument.FormFields("bkReflect").Result = strX
End If
More code . . .

I have read through some books and consulted with my coworkers and I
haven't found why the two did not work. When referring to checkboxes
doesn't .value = (true, 1, or checked) all mean the same? There are
other lines of code dealing with textboxes and optionboxes in the same
procedure, but that shouldn't affect it.

Thanks in advance!
 
J

Jay Freedman

Hi Dale,

The answer to your question
When referring to checkboxes
doesn't .value = (true, 1, or checked) all mean the same?

is "no".

In VBA, the numeric value of True is -1. The value of a checked
checkbox form field is True or -1.

The predefined value Checked, which does equal 1, applies only to
tristate check boxes used in Word's dialogs. These are the ones, like
the Strikethrough box in the Format > Font dialog, that can be
checked, unchecked, or gray (you'll see the gray value if you select
some text that's partially struck through, and then open the Font
dialog).
 

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