Access.2007.VBA.Bibl..

(John Hannent) #1

Must declare this variable as Object because declaring it as Word.CustomProperties doesn’t work:


Dim prps As Object

Must declare this variable as Object because declaring it as Word.CustomProperty doesn’t work:


Dim prp As Object

Set appWord = GetObject(Class:=”Word.Application”)

strTemplateDir = GetContactsTemplatesPath()
Debug.Print “Templates directory: “ & strTemplateDir
strLetter = strTemplateDir & “DocProps.dot”
Debug.Print “Letter: “ & strLetter

Set docs = appWord.Documents
docs.Add strLetter
Set doc = appWord.ActiveDocument
Set prps = doc.CustomDocumentProperties
For Each prp In prps
Debug.Print “Property name: “ & prp.Name
Next prp

ErrorHandlerExit:
Exit Function

ErrorHandler:
If Err = 429 Then
‘Word is not running; open Word with CreateObject
Set appWord = CreateObject(Class:=”Word.Application”)
Resume Next
Else
MsgBox “Error No: “ & Err.Number _
& “; Description: “ & Err.Description
Resume ErrorHandlerExit
End If

End Function

Using a Query to Concatenate Data for Export ..............................................

I like to create a select query to use as the data source for merging Access data to Word, concate-
nating data from various fields as needed for best results when working with Word documents.
One field concatenates name, job title, and company name information, using the IIffunction to
avoid creating blank lines, and another creates a single field with address information. This tech-
nique ensures that you won’t see blank lines in the address block in a letter, or on a label, even if


Working with Word Documents and Templates 6

Free download pdf