DocVariable field

S

Steve C

I am trying to use this field in a template to insert the same information
into all document headers and footers based on this template (a Different
First Page header/footer is needed). The header & footer on all pages will
be the same, with the exception that the first page header is blank.

The footers all contain this field: {DOCVARIABLE Category \* MERGEFORMAT},
while the headers contain {DOCVARIABLE Supervisor \* MERGEFORMAT}. Category
is supplied by a combo box on a form, while Supervisor is supplied by a text
box.

Below is my code to insert that information, but nothing gets inserted when
I click the OK button on my form to view the headers & footers afterward.
What am I missing? Thanks!

Private Sub cmdOK_Click()
ActiveDocument.Variables("Category").Value = cboCategory.Value
ActiveDocument.Variables("Supervisor").Value = txtSupervisor.Text
ActiveDocument.Fields.Update
End Sub

Steve C
 
J

Jonathan West

Hi Steve

Unfortunately, ActiveDocument.Fields.Update doesn't update the fields in
headers

I'm assuming that you have a single section in your document, and a separate
first page header. In this case, you need to add the following code at the
end of the macro

With ActiveDocument.Sections(1)
.Header(wdHeaderFooterFirstPage).Range.Fields.Update
.Header(wdHeaderFooterPrimary).Range.Fields.Update
.Footer(wdHeaderFooterFirstPage).Range.Fields.Update
.Footer(wdHeaderFooterPrimary).Range.Fields.Update
End With
 
S

Steve C

Jonathan,

A belated thank you for the code below. It set me on the right path. FYI:
The code should read .Headers and .Footers (plural). Thanks again!
 

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

Ask a Question

Top