setting DOCVARIABLE from Access

B

Bill Agee

I want to update a Word template with name, address, etc and save it as a
Word document from Microsoft ACCESS. My Word template has the several
DOCVARIABLES such as:



{ DOCVARIABLE "Attyfirm"}

{ DOCVARIABLE "Address1"}

etc.



In Access I am able to open the Word template with

Set WordDoc=WordApp.Documents.Open ("path.DTLetter.Dot")

and then follow with additional VBA statements
WordDoc.Variables("AttyFirm").Value=[wAttyFirm]

WordDoc.Variables("Address1").Value=[wAddress1]



Etc.



WordDoc.Fields.Update

WordDoc.SaveAs Filename=wfilename

WordDoc.Close



The document is correctly saved in the right folder with the proper name,
however, no updates occurred in the saved document, the {DOCVARIABLES
"varnames"} remained unchanged.



Any suggestions?
 
D

Doug Robbins - Word MVP

Hi Bill,

Rather than open the template, you should create a document from the
template using


Set WordDoc=WordApp.Documents.Add ("path.DTLetter.Dot")

The rest of your code should work as long as [wAttyFirm] actually returns
the information.

If the { DOCVARIABLE } fields are in the header/footer, a simple
WordDoc.Fields.Update will not cause them to be updated. You will need to
interate through the Sections and Headers/Footers of the document and update
the fields in the .Range of each.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

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