Access.2007.VBA.Bibl..

(John Hannent) #1
FIGURE 6.18

A combo box for selecting a Word template for merging data from Access.


The procedure then calls one of four procedures with the document file name (including path) and
extension as arguments, depending on the merge type.

The cmdCreateDocuments_Clickprocedure is listed as follows:

Private Sub cmdCreateDocuments_Click()

On Error GoTo ErrorHandler

Dim cbo As Access.ComboBox
Dim strCompanyName As String
Dim strContactName As String
Dim strJobTitle As String
Dim strTestFile As String
Dim strWordTemplate As String
Dim strTest As String
Dim strDocType As String
Dim strMergeType As String
Dim strExtension As String

Check that a document has been selected:

Set cbo = Me![cboSelectDocument]
strWordTemplate = Nz(cbo.Value)
If strWordTemplate = “” Then
MsgBox “Please select a document”
cbo.SetFocus
cbo.Dropdown
GoTo ErrorHandlerExit
End If

strTemplatePath = GetContactsTemplatesPath()
Debug.Print “Template path: “ & strTemplatePath
strWordTemplate = strTemplatePath & strWordTemplate

Working with Word Documents and Templates 6

Free download pdf