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

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 (here). After that, you can post your question and our members will help you out.