Access.2007.VBA.Bibl..

(John Hannent) #1
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
.ApplyStyleRowBands = True
.ApplyStyleColumnBands = False
End With

Insert contact data from Access table into Word table:


Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(“tblContacts”)
Do While Not rst.EOF
With appWord.Selection
.TypeText rst![LastName] & “, “ & rst![FirstName]
.MoveRight Unit:=wdCell, Count:=2
End With
rst.MoveNext
Loop

Delete the last, blank row:


appWord.Selection.Rows.Delete

Sort contact names alphabetically:


doc.Tables(1).Select
appWord.Selection.Sort ExcludeHeader:=False, _
FieldNumber:=”Column 1”, _
SortFieldType:=wdSortFieldAlphanumeric, _
SortOrder:=wdSortOrderAscending

ErrorHandlerExit:
Set appWord = Nothing
Exit Sub

ErrorHandler:
If Err = 429 Then

Word is not running; open Word with CreateObject:


Set appWord = CreateObject(“Word.Application”)
Resume Next
Else
MsgBox “Error No: “ & Err.Number _
& “; Description: “ & Err.Description
Resume ErrorHandlerExit
End If

End Sub

Creating Word Documents from Access 2

Free download pdf