View Single Post
  #9   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Checkbox Macro Help

While I disagree with your apparent dismissal of MS Forms controls which are
still widely used in preference to ActiveX controls, the point I was trying
to make was based on a misreading of the point that you were making, where
the value is false. My error!

--

Graham Mayor - Word MVP

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



Scott M. wrote:
A few things....

1. Your code below is based on using the "MS Forms" controls, rather
than the ActiveX controls that superceded them about 15 years ago.
2. Nonetheless, when I create an MS Forms textbox and checkbox as you
indicated, your code works perfectly fine as expected, so I don't
know what problem you thought would be created, but none was. The
code also works identically when the "=True" portion is omitted as I
indicated. 3. If you use the modern ActiveX set of controls, the need to
access
them via the more antiquated
"ActiveDocument.FormFields("controlName")" paradigm becomes
irrelevant, you simply access the control via it's name, and can
immediately access its properties. For example:
If CheckBox1.Value Then
TextBox1.Text = "YES"
Else
TextBox1.Text = "NO"
End If

Ultimately, I fail to see whatever point you were trying to make. It
is true now and has always been true (in any language) that a
compiler will evaluate an "If" statement to see if its test
expression is equal to the Boolean 'True". So, when evaluating an
expression that returns a Boolean anyway, the extra check for True is
simply redundant.
It's no different than writing:

If x = 7 = True then ... (which works, but no one would ever write)

vs.

If x = 7 Then ... (the compiler checkes to see if the results of the
expression is True without having to be told that this is what to
look for)
-Scott


"Graham Mayor" wrote in message
...
You think so? Try this.

Create a check box and a text form field - leave their default names.
Run the following macro with the box checked

If ActiveDocument.FormFields("Check1").CheckBox.Value = True Then
ActiveDocument.FormFields("Text1").Result = "YES"
End If

Now run it again with the box unchecked.

--

Graham Mayor - Word MVP

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




Scott M. wrote:
FYI: No need to check for true explicitly in an "If" statement as
the compiler always checks for the "truthiness" of your expression.


If ActiveDocument.FormFields("Check1").CheckBox.Value then
'Code to populate the table
Else
'Code to remove data from the table
End If

-Scott


"Doug Robbins - Word MVP" wrote in message
...
Your macro should check for the status of the checkbox

If ActiveDocument.FormFields("Check1").CheckBox.Value = True then
'Code to populate the table
Else
'Code to remove data from the table
End If

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of
my services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"Karin" wrote in message
...
I want to have 3-4 checkboxes at top of document. If checkbox
Apple (for example) is checked, I want to run a macro that fills
in fields in a table.
(I've written the macro) The problem is I need to be able to undo
the macro
if they click it again (turning it off). Right now, it runs the
same macro
again when it's clicked again. Any guidance would be appreciated.