change color of checkbox with click event?

Discussion in 'Word Programming' started by got questions via OfficeKB.com, May 8, 2008.

  1. Am creating a Word form with protected fields in Word 2003.

    When critical checkbox's are clicked, I would like the box w/check to become
    bold and change to red in order to stand out from the black of the other text.
    Is there a way to do this?

    Also - could this be countered, say, with a shift or ctrl click to change
    back to black and clear the check?

    Regards...

    --
    Message posted via OfficeKB.com
    http://www.officekb.com/Uwe/Forums.aspx/word-programming/200805/1
     
    got questions via OfficeKB.com, May 8, 2008
    #1
    1. Advertisements

  2. You can't do the bold, but the following will toggle the color of the
    CheckBox to which the bookmark name of "Check2" is assigned if a macro
    containing this code is run on exit from that checkbox

    With ActiveDocument
    .Unprotect
    With .FormFields("Check2")
    If .CheckBox.Value = True Then
    .Range.Font.Color = wdColorRed
    Else
    .Range.Font.Color = wdColorAutomatic
    End If
    End With
    .Protect wdAllowOnlyFormFields, NoReset
    End With

    --
    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

    "got questions via OfficeKB.com" <u14120@uwe> wrote in message
    news:83dcc08e2802f@uwe...
    > Am creating a Word form with protected fields in Word 2003.
    >
    > When critical checkbox's are clicked, I would like the box w/check to
    > become
    > bold and change to red in order to stand out from the black of the other
    > text.
    > Is there a way to do this?
    >
    > Also - could this be countered, say, with a shift or ctrl click to change
    > back to black and clear the check?
    >
    > Regards...
    >
    > --
    > Message posted via OfficeKB.com
    > http://www.officekb.com/Uwe/Forums.aspx/word-programming/200805/1
    >
     
    Doug Robbins - Word MVP, May 9, 2008
    #2
    1. Advertisements

  3. Doug: my thanks for your reply, though I do have another question. I notice
    you use unprotect/protect to run the code. What predicates whether the
    document has to be 'unprotected' to run code? Just about all of the code I
    have runs either with protection on or in an unprotected section.

    got questions wrote:
    >Am creating a Word form with protected fields in Word 2003.
    >
    >When critical checkbox's are clicked, I would like the box w/check to become
    >bold and change to red in order to stand out from the black of the other text.
    >Is there a way to do this?
    >
    >Also - could this be countered, say, with a shift or ctrl click to change
    >back to black and clear the check?
    >
    >Regards...


    --
     
    got questions via OfficeKB.com, May 12, 2008
    #3
  4. got questions via OfficeKB.com

    Jay Freedman Guest

    Try running Doug's code without the Unprotect. The result will be a run-time
    error 4605, "This method or property is not available because the object
    refers to a protected area of the document".

    In a protected document, any attempt to change anything about a formfield
    other than its .Result (or, for a checkbox formfield, its .Checkbox.Value)
    will get that error, as will any attempt to change text that isn't inside a
    formfield.

    --
    Regards,
    Jay Freedman
    Microsoft Word MVP
    Email cannot be acknowledged; please post all follow-ups to the newsgroup so
    all may benefit.

    got questions via OfficeKB.com wrote:
    > Doug: my thanks for your reply, though I do have another question.
    > I notice you use unprotect/protect to run the code. What predicates
    > whether the document has to be 'unprotected' to run code? Just about
    > all of the code I have runs either with protection on or in an
    > unprotected section.
    >
    > got questions wrote:
    >> Am creating a Word form with protected fields in Word 2003.
    >>
    >> When critical checkbox's are clicked, I would like the box w/check
    >> to become bold and change to red in order to stand out from the
    >> black of the other text. Is there a way to do this?
    >>
    >> Also - could this be countered, say, with a shift or ctrl click to
    >> change back to black and clear the check?
    >>
    >> Regards...
     
    Jay Freedman, May 12, 2008
    #4
  5. got questions via OfficeKB.com

    rm3 Guest

    Doug Robbins - Word MVP wrote on 05/08/2008 20:10 ET
    > You can't do the bold, but the following will toggle the color of th
    > CheckBox to which the bookmark name of "Check2" is assigned if
    > macr
    > containing this code is run on exit from that checkbo
    >
    > With ActiveDocumen
    > .Unprotec
    > With .FormFields("Check2"
    > If .CheckBox.Value = True The
    > .Range.Font.Color = wdColorRe
    > Els
    > .Range.Font.Color = wdColorAutomati
    > End I
    > End Wit
    > .Protect wdAllowOnlyFormFields, NoRese
    > End Wit
    >
    > Hope this helps
    >
    > Please reply to the newsgroup unless you wish to avail yourself of m
    > services on a paid consulting basis
    >
    > Doug Robbins - Word MV
    >
    > "got questions via OfficeKB.com" wrote in messag
    > news
    >> Am creating a Word form with protected fields in Word 2003
    >>
    >> When critical checkbox's are clicked, I would like the box w/check t
    >> becom
    >> bold and change to red in order to stand out from the black of the othe
    >> text
    >> Is there a way to do this
    >>
    >> Also - could this be countered, say, with a shift or ctrl click to chang
    >> back to black and clear the check
    >>
    >> Regards..
    >>
    >> Message posted via OfficeKB.co
    >> http://www.officekb.com/Uwe/Forums.aspx/word-programming/200805/
    >>
    >>
    >>

    >

    Hi

    This is very useful

    However, can you please tell me how to apply it to all the check boxes in m
    report from check1 to check158

    Thank you so much!
     
    rm3, Nov 5, 2012
    #5
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. wendy
    Replies:
    0
    Views:
    119
    wendy
    Jan 22, 2004
  2. CJ
    Replies:
    1
    Views:
    144
    Doug Robbins - Word MVP
    Jul 12, 2007
  3. darius

    Convert wingding checkbox to toolbox checkbox?

    darius, Oct 5, 2007, in forum: Word Programming
    Replies:
    3
    Views:
    244
    darius
    Oct 5, 2007
  4. Chuck
    Replies:
    0
    Views:
    118
    Chuck
    Oct 26, 2007
  5. bind checkbox to merge field

    , May 13, 2008, in forum: Word Programming
    Replies:
    1
    Views:
    268
    Doug Robbins - Word MVP
    May 13, 2008
  6. professor1554

    Automating Checkbox Fields in Word

    professor1554, Jan 22, 2009, in forum: Word Programming
    Replies:
    4
    Views:
    154
    professor1554
    Jan 23, 2009
  7. DeanL

    Need a checkbox of a word document

    DeanL, Mar 18, 2009, in forum: Word Programming
    Replies:
    2
    Views:
    84
    DeanL
    Mar 19, 2009
  8. EagerGit
    Replies:
    1
    Views:
    226
    Jay Freedman
    Apr 28, 2010
Loading...