Hi Cindy,
First, you need to know that SectionPages is a *field*, not a *property* of
anything in VBA. Word uses fields to insert all sorts of calculated values
into documents. Please read at least Word's (regular, not VBA) help topic
about fields and field codes so you know what you're dealing with.
Second, your code that opens the document gives me fits. In Word, "template"
has a special meaning. A template is not an ordinary document that you open
and fill in; it's a separate file that's used like a cookie-cutter to make
other documents. Once a template is created for a specific purpose, it's
rarely opened or altered -- you do all the work in documents *based on* the
template. (See
http://word.mvps.org/FAQs/Customization/CreateATemplatePart1.htm.) In VBA,
you would use
Set doc = .Documents.Add(template_name)
where the template called template_name already exists, and that command
creates a new document *based on* the template. Use .Documents.Open only for
regular documents, unless you mean to alter the template itself.
My best suggestion is that you should create a Word template specifically
for this kind of document, in which the footer is already set up with the
Page field, the SectionPages field, and the CreateDate field in place. The
footer of the template can also contain a bookmark, which would then be
present in the document, and the Access code can insert its text at the
bookmark in the document (see
http://word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm).
Another consideration is that you have to unlink the footer of Section 3
from the footer of Section 2, or else any changes you make will appear in
both footers. You can do that in the template by going into the footer area
of Section 3 and clicking the Same As Previous button on the Footer toolbar
to turn it off, and then the document will inherit this from the template.
You would also want to restart page numbering at page 1 in Section 3
(otherwise your footer will say nonsense like "Page 3 of 1").
In Word, by default the footers are formatted with a paragraph style named
Footer, which contains a center-aligned tabstop at the middle of the text
width and a right-aligned tabstop at the right margin. Use tab characters
(vbTab) to separate the pieces of your footer, and they'll automatically
align correctly. Also, you can't use ".PageNumbers.Add" (equivalent to the
Insert > Page Number dialog) to put in a page number that will be part of
the "Page x of y" construction -- that kind of page number is stuck into a
frame that floats over the footer text.
If you really want to do this footer stuff the hard way through VBA code,
here's an example of what you need to do to insert the text and fields in
the right places (I assume your document already has at least three
sections).
Dim oRg As Word.Range
With ActiveDocument ' in Access, use "With doc"
Set oSec = .Sections(3)
With oSec.Footers(wdHeaderFooterPrimary)
.LinkToPrevious = False ' turn off Same As Previous
.PageNumbers.RestartNumberingAtSection = True
.PageNumbers.StartingNumber = 1
End With
Set oRg = oSec.Footers(wdHeaderFooterPrimary).Range
' left side (text actually from Access DB)
' and start of center
oRg.Text = "text" & vbTab & "Page "
Set oRg = oSec.Footers(wdHeaderFooterPrimary).Range
oRg.Collapse direction:=wdCollapseEnd
' Page field
.Fields.Add Range:=oRg, Type:=wdFieldPage
Set oRg = oSec.Footers(wdHeaderFooterPrimary).Range
oRg.Collapse direction:=wdCollapseEnd
oRg.Text = " of "
Set oRg = oSec.Footers(wdHeaderFooterPrimary).Range
oRg.Collapse direction:=wdCollapseEnd
' SectionPages field
.Fields.Add Range:=oRg, Type:=wdFieldSectionPages
Set oRg = oSec.Footers(wdHeaderFooterPrimary).Range
oRg.Collapse direction:=wdCollapseEnd
oRg.Text = vbTab
Set oRg = oSec.Footers(wdHeaderFooterPrimary).Range
oRg.Collapse direction:=wdCollapseEnd
' CreateDate field
.Fields.Add Range:=oRg, Type:=wdFieldCreateDate, _
Text:="\@MM/dd/yyyy"
End With
Set oRg = oSec.Footers(wdHeaderFooterPrimary).Range
oRg.Fields.Update