Access to Word

C

Chris Watkins

Hi

I'm fine-tuning an Access DB that makes a table from a
query and also adds a file-location for a linked Word file.
I've set up the Word Merge document with the merge fields
from the table together with an includetext field to then
link in the extra Word file. - looks like:
{IF 1 = 1 "{INCLUDETEXT "{MERGEFIELD ScriptLocation}"}"}

I open this Word merge document from Access and can then
View the Merged Data, BUT it doesn't work all the time!
I usually have to highlight the includetext field and
press F9 to get this first record text included - this
usually works.
Is there any way I can setup some macros to automatically
view the first record and then view the next record with
everything being updated? I also need to automatically
update the NUMPAGES field.

any help most appreciated!
chhers
chris
 
D

Doug Robbins

ActiveDocument.Fields.Update

will update the fields in the body of the document.

or

ActiveDocument.PrintPreview
ActiveDocument.ClosePrintPreview

should get everything updated (including headers and footers) as long as the
Update fields at Printing option is set under Tools>Options.

Otherwise, it's a matter of iterating through each of the storyranges in the
document and updating the fields.

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
C

Chris Watkins

Thanks Doug

Have since got most of it going ok with macros to get next
record and then update the fields in the document.
But, a problem still remains with the NUMPAGES field.
Seems that linking in the extra doc (usually some 2-4
pages in length) with INCLUDETEXT takes so long that the
update for NUMPAGES happens before all of the doc is
inserted ... hence incorrect NUMPAGES!
I've tried to find some sort of delay mechanism before
updating NUMPAGES.
any clues?

cheers
chris
 
D

Doug Robbins

The following will update the IncludeText fields and then the numpages
fields

Dim afield As Field
For Each afield In ActiveDocument.Fields
If afield.Type = wdFieldIncludeText Then
afield.Update
End If
Next afield
For Each afield In ActiveDocument.Fields
If afield.Type = wdFieldNumPages Then
afield.Update
End If
Next afield


--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
C

Chris Watkins

Thanks again Doug

I've already done that though and still doesn't actually
refelect the true number of pages.
So I tried this:
Application.OnTime When:=Now + TimeValue("00:00:02"), _
Name:="UpdatePageNums"
to run another macro, called "UpdatePageNums" to physical
select the numpages field and update it.
This works, I reckon 'cos the docs are loaded within 2
seconds, then I move the cursor and select the field and
update, but its not pretty!
I'm also worried that it will still fail if a larger doc
doesn't get loaded within the 2 seconds.
Any suggestions appreciated!

cheers
chris
 

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