O'Reilly logo

Access™ 2007 VBA Bible: For Data-Centric Microsoft® Office Applications by Helen Feddema

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 2. Creating Word Documents from Access

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.

Note

For more complex and realistic examples of exporting Access data to Word documents, see Chapters 6 and 12.

Note

The sample database for this chapter is Access to Word.accdb.

Filling Word Documents with Access Data Using the TypeText Method

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

Note

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required