Access.2007.VBA.Bibl..

(John Hannent) #1
The TypeText Method ....................................................................................

For simple documents such as mailing labels, where you just need to insert a block of text from
Access, without fancy formatting, the TypeText method of the Word Selection object can be useful.
If you select the Avery 5160 (TypeText) selection from the Select Document combo box on
frmMergeToWord, you will get a Word document in the form of a table with cells of the right size
to print on the label sheets, as shown in Figure 6.21.

FIGURE 6.21
An Avery 5160 labels document filled with data from Access.

You can also create a list-type document using the TypeText method, filling a table with
data from Access records, one record per row. Figure 6.22 shows such a document,
using one of the new Word 2007 table themes and the new banded rows feature.

The MergeTypeTextprocedure (listed as follows) writes data from variables directly to cells in a
table, moving to the next cell using the MoveRightmethod:

Private Sub MergeTypeText(strWordTemplate As String, _
strExtension As String)

On Error GoTo ErrorHandler

NEW FEATURENEW FEATURE

Part II Writing VBA Code to Exchange Data between Office Components

Free download pdf