Results 1 to 13 of 13
  1. #1
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

    I have a .docm that has 4 checkboxes (FormFields) in a row I would like to have the last check box when selected turn the check red and is it possible to remove the grey highlight that are in the checkboxes.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You can color an entire forms check box, not just the interior. To color it conditionally would probably require some sophisticated coding.

    The gray background can be turned on and off using the Shading button on the Forms toolbar. The setting is stored with the document.

  3. #3
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='785847' date='22-Jul-2009 16:41']You can color an entire forms check box, not just the interior. To color it conditionally would probably require some sophisticated coding.

    The gray background can be turned on and off using the Shading button on the Forms toolbar. The setting is stored with the document.[/quote]
    Hi HansV
    How might i achieve this this method "color an entire forms check box", then I'll check it out to see if it will word for my application

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Let's say that the check box has bookmark name "Check4". The code to color it red would be

    ' Unprotect the document
    ActiveDocument.Unprotect
    ' Color the check box
    ActiveDocument.FormFields("Check4").Range.Font.Col or = wdColorRed
    ' Reprotect the document
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

  5. #5
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking

    [quote name='HansV' post='785851' date='22-Jul-2009 16:55']Let's say that the check box has bookmark name "Check4". The code to color it red would be

    ' Unprotect the document
    ActiveDocument.Unprotect
    ' Color the check box
    ActiveDocument.FormFields("Check4").Range.Font.Col or = wdColorRed
    ' Reprotect the document
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True[/quote]
    Hi Hans
    Its not quite what I'm looking for. I know I'm asking for a lot, and I thank you for your patance
    Is there a way to have it toggle back and forth and possibily a larger X not in pt but bolder

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You could add a line with

    ...Font.Bold = True

    To reset the check box, use the same code but with

    .Font.Color = wdColorBlack
    .Font.Bold = False

  7. #7
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

    [quote name='HansV' post='785877' date='23-Jul-2009 01:30']You could add a line with

    ...Font.Bold = True

    To reset the check box, use the same code but with

    .Font.Color = wdColorBlack
    .Font.Bold = False[/quote]

    Hi HansV
    I have been having a problem with trying to have my check box toggle back and forth. So then I tried using FormField options and applying this code at entry

    Code:
    Sub Macro8()
    '
    ' Macro8 Macro
    '
    '
    ‘Entry: Empty box not checked
    
    ' Unprotect the document
    ActiveDocument.Unprotect
    ' Color the check box
    If ActiveDocument.FormFields("Check4").CheckBox = False Then
    ActiveDocument.FormFields("Check4").Range.Font.Color = wdColorBlack
    ' Reprotect the document
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    	End If
    End Sub
    and on Exit

    Code:
    Sub Macro9()
    '
    ' Macro9 Macro
    '
    '
    ‘Exit: This is when box is checked
    ' Unprotect the document
    ActiveDocument.Unprotect
    ' Color the check box
    If ActiveDocument.FormFields("Check4").CheckBox = True Then
    ActiveDocument.FormFields("Check4").Range.Font.Color = wdColorRed
    ' Reprotect the document
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    	End If
    End Sub
    Am I on the right track or have I taken a wrong turn.........
    also I was having a problem with getting the Bold to work with the Red X
    Code:
    Font.Bold = True

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Your code is based on a misunderstanding. The On Entry macro is run each time the user tabs into or clicks on the check box, whether it was ticked or not. And the On Exit macro is run each time the user tabs out of or clicks outside the check box, whether it has been ticked or not. You do not need an On Entry macro, only an On Exit macro.

    I notice that setting font color has a visible result, but making the font bold or not bold doesn't, you'll have to forget about that.

    Here is a working version of the On Exit macro:

    Code:
    Sub Macro9()
      ' Unprotect the document
      ActiveDocument.Unprotect
      ' Color the check box
      With ActiveDocument.FormFields("Check4")
    	If .CheckBox.Value = True Then
    	  .Range.Font.Color = wdColorRed
    	Else
    	  .Range.Font.Color = wdColorBlack
    	End If
      End With
      ' Reprotect the document
      ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    End Sub
    Notice that I use Checkbox.Value to get the status of the text box.

  9. #9
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking

    [quote name='HansV' post='786439' date='27-Jul-2009 11:51']Your code is based on a misunderstanding. The On Entry macro is run each time the user tabs into or clicks on the check box, whether it was ticked or not. And the On Exit macro is run each time the user tabs out of or clicks outside the check box, whether it has been ticked or not. You do not need an On Entry macro, only an On Exit macro.

    I notice that setting font color has a visible result, but making the font bold or not bold doesn't, you'll have to forget about that.

    Here is a working version of the On Exit macro:

    Code:
    Sub Macro9()
      ' Unprotect the document
      ActiveDocument.Unprotect
      ' Color the check box
      With ActiveDocument.FormFields("Check4")
    	If .CheckBox.Value = True Then
    	  .Range.Font.Color = wdColorRed
    	Else
    	  .Range.Font.Color = wdColorBlack
    	End If
      End With
      ' Reprotect the document
      ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    End Sub
    Notice that I use Checkbox.Value to get the status of the text box.[/quote]
    Hi HansV
    Thank you, I got it to work I just have to Tab out of box the make changes
    I thank you for helping I always enjoy learnig from my mistakes

  10. #10
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking

    Hi HansV
    I have a further question on the Check Boxes. On my report I have 40 different questions that are being asked. With each question having 4 Check Boxes to choose from. The forth Check Box on each question is the Check box that I want to use the code.
    My question is ? Since there are 40 Check Boxes that need to use this same code. And I believe each Check Box requires a different name. What changes do I need to make.....

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You could use code like this

    Code:
    ' Exit macro for Check4
    
    Sub Exit4()
      Call ExitCheck("Check4")
    End Sub
    
    ' Exit macro for Check8
    
    Sub Exit8()
      Call ExitCheck("Check8")
    End Sub
    
    ' Add macro for each check box
    ...
    
    ' Common code
    
    Sub ExitCheck(strName As String)
      ' Unprotect the document
      ActiveDocument.Unprotect
      ' Color the check box
      With ActiveDocument.FormFields(strName)
    	If .CheckBox.Value = True Then
    	  .Range.Font.Color = wdColorRed
    	Else
    	  .Range.Font.Color = wdColorBlack
    	End If
      End With
      ' Reprotect the document
      ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    End Sub

  12. #12
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='786544' date='28-Jul-2009 07:54']You could use code like this

    Code:
    ' Exit macro for Check4
    
    Sub Exit4()
      Call ExitCheck("Check4")
    End Sub
    
    ' Exit macro for Check8
    
    Sub Exit8()
      Call ExitCheck("Check8")
    End Sub
    
    ' Add macro for each check box
    ...
    
    ' Common code
    
    Sub ExitCheck(strName As String)
      ' Unprotect the document
      ActiveDocument.Unprotect
      ' Color the check box
      With ActiveDocument.FormFields(strName)
    	If .CheckBox.Value = True Then
    	  .Range.Font.Color = wdColorRed
    	Else
    	  .Range.Font.Color = wdColorBlack
    	End If
      End With
      ' Reprotect the document
      ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    End Sub
    [/quote]

    Hi HansV
    Thank you it worked great!!!!!!

  13. #13
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post

    Hi HansV
    Since the bold was not an option I made some adjustments so that I could apply shading to Check box when checked.
    I thank you for all your help, it has given me a better understanding with VBA. I'm still a ways off, but on my way.

    ' Exit macro for Check1
    Sub Exit1()
    Call ExitCheck("Check1")
    End Sub
    ' Exit macro for Check2
    Sub Exit2()
    Call ExitCheck("Check2")
    End Sub
    ' Exit macro for Check3
    Sub Exit3()
    Call ExitCheck("Check3")
    End Sub
    ' Exit macro for Check4
    Sub Exit4()
    Call ExitCheck("Check4")
    End Sub
    ' Add macro for each check box
    ' Common code
    Sub ExitCheck(strName As String)
    ' Unprotect the document
    ActiveDocument.Unprotect ("")
    ' Color the check box
    With ActiveDocument.FormFields(strName)
    If .CheckBox.Value = True Then
    .Range.Font.Color = wdColorBlack
    .Range.Font.Shading.BackgroundPatternColor = RGB(250, 120, 110)
    Else
    .Range.Font.Color = wdColorBlack
    .Range.Font.Shading.BackgroundPatternColor = wdColorAutomatic

    End If
    End With
    ' Reprotect the document
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""

    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •