Re: Setting color of table cell based on list selection

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Your reference to a tag and the lack of results from the CheckFormFields macro
indicate that the "drop down fields" you used are actually content controls and
not formfields. That's why there are no members of the FormFields collection.

Either you can replace those content controls with dropdown formfields from the
Legacy Tools button (fourth from the left in the second row of the Controls
group), or you can change the macro to work with the content controls.

You can't refer to a content control directly by its tag the way you could refer
to a formfield by its bookmark name; instead, you must loop through the
collection until you find one with the desired tag (and note that tags aren't
necessarily unique). The modified code would be

Sub ColorRiskCell()
Dim oCC As ContentControl

With ActiveDocument
For Each oCC In .ContentControls
If oCC.Tag = "Risk" Then Exit For
Next

If Not oCC Is Nothing Then
If oCC.Range.Text = "High" Then
.Tables(1).Cell(3, 3).Shading.BackgroundPatternColor _
= wdColorRed
Else
.Tables(1).Cell(3, 3).Shading.BackgroundPatternColor _
= wdColorGreen
End If
End If
End With
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.

On Sat, 28 Mar 2009 19:41:10 -0700 (PDT), Alan <jalanthomas@xxxxxxxxxxx> wrote:

This code should do it, but I am having problems referring to the drop-
down list I inserted into the table (display shows "Risk Level", tag =
"Risk".

Sub ColorRiskCell()
With ActiveDocument
If .FormFields("Risk").DropDown.Value = "High" Then
ActiveDocument.Tables(1).Cell(3,
3).Shading.BackgroundPatternColor = wdColorRed
Else
ActiveDocument.Tables(1).Cell(3,
3).Shading.BackgroundPatternColor = wdColorGreen
End If
End With
End Sub

So, I tried to print out the names of all the form fields in the
document, but got no output:

Sub CheckFormFields()
Dim aField As FormField
For Each aField In ActiveDocument.FormFields
Debug.Print "Form Field Name: " & aField.Name
Debug.Print "Form Field Type: " & aField.Type
Next aField
End Sub

I cannot use Excel, because this is a form in Word.

So, I am confused. --- Alan
.



Relevant Pages

  • Re: Conditonal List Processing
    ... your example 'C' code grouped the controls under labels, ... then compare the tag property of each control to the variable to ... Private Sub isLockControls ... This permits disabling to be started from a selected point determined by ...
    (microsoft.public.access.formscoding)
  • reuse code inquiry
    ... I am a perl beginner and I am suggested to parse HTML by using ... sub parse_html { ... # incomplete tag. ... if ($routine eq "") { ...
    (comp.lang.perl.misc)
  • Referencing A Subprocedures Name (Re-post)
    ... The textboxes I'm using are not on a form, ... The trick is to iterate through all the controls, ... >Sub PastReply ... >checkboxes to the collection that hosts the classes. ...
    (microsoft.public.excel.programming)
  • Re: recordsetclone mis-usage?
    ... When I say select all the controls, I literally mean "select ALL the ... In comboGOTOotherrecord_afterupdate, you still need the .Edit, because ... Sub Newscreenchangectlcolor() ... sometimes I get an error message: ...
    (microsoft.public.access.formscoding)
  • Re: TabStrip control with XP Themes
    ... Public Sub Hook ... You'll need the API ... > private defWindowProc as long ... Most things work fine except for controls that sit ...
    (microsoft.public.vb.controls)