IN THIS CHAPTER
Word documents and templates
Working with Word bookmarks
Working with the TypeText method
Working with Word document properties
Working with form fields
Working with tables
If you need to produce documents with more sophisticated formatting than is available in an Access report, your best option is to create Word documents and fill them with data from Access. There are many ways to export data from Access to Word; which one to use depends on the circumstances, the type of data to export, and user preferences. This chapter discusses the various types of Word documents you can create and the methods you can use to fill them with data, with basic examples.
The sample database for this chapter is Access to Word.accdb.
You can create a blank Word document (based on the default Word template) with two lines of code:
Set appWord = GetObject(, "Word.Application") Set doc = appWord.Documents.Add
In most of my Automation code working with other Office applications (Word, Excel, and Outlook), I use the
GetObject function in the body of a procedure, to set a reference to the running instance of the application, if there is one; the procedure's error handler runs
CreateObject if the application is not already running (see the code samples later in this chapter ...