View Single Post
  #11   Report Post  
Posted to microsoft.public.word.docmanagement
Pamela Denchfield Pamela Denchfield is offline
external usenet poster
 
Posts: 19
Default How do content control fields work?

Is there a way to incorporate the auto-updated content controls without
resorting to VBA or other coding? The templates freely downloaded from Office
Online seem to have these already incorporated, dependent on standard
document properties. It would be nice if I could create these myself, too.
--
Thanks,
Pamela Denchfield


"Greg Maxey" wrote:

Here is one way and I am working on others to update my website:

Use the Document_ContentConrolOnExit event to write the text value of the
current Content Control to a custom document property. Then use DocProperty
fields at the other location in your document to repeat the data:

Private Sub Document_ContentControlOnExit(ByVal currentCC As ContentControl,
Cancel As Boolean)
Dim oDoc As Word.Document
Set oDoc = ActiveDocument
Select Case currentCC.Title
Case "Client_Name"
On Error Resume Next
oDoc.CustomDocumentProperties("Client_Name").Value =
currentCC.Range.Text
If Err.Number = 5 Then
oDoc.CustomDocumentProperties.Add _
Name:="Client_Name", LinkToContent:=False,
Value:=currentCC.Range.Text, _
Type:=msoPropertyTypeString
End If
On Error GoTo 0
Case Else
'Do nothing
End Select
UpdateDocumentFields
End Sub
Sub UpdateDocumentFields()
Dim pRange As Word.Range
Dim iLink As Long
iLink = ActiveDocument.Sections(1).Headers(1).Range.StoryT ype
For Each pRange In ActiveDocument.StoryRanges
Do
pRange.Fields.Update
Set pRange = pRange.NextStoryRange
Loop Until pRange Is Nothing
Next
End Sub

--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.


piersonal wrote:
The sites make really good reading thank you. The one main question
that I had was with how to reference a Content Control. A template
that I downloaded had a Content Control for the Title, which was
repeated on the next page. Update one and the other would update.

This is good for existing Property fields, but can we create custom
ones? I want to have users enter the customer name on the front page
(into a Content Control) and to have this information repeated in
other areas, but I cannot for the life of me figure out how to do
this.