Dim objWord As Word.Application
Dim rst As Recordset
Dim strSQL As String
' Launch Word and load the invoice template
Set objWord = New Word.Application
objWord.Documents.Add _
Application.CurrentProject.Path & "\CMA.dot"
objWord.Visible = True
' Add header information using predefined bookmarks
''''''' With objWord.ActiveDocument.Bookmarks
''''''' .Item("OrderID").Range.Text = frmOrder.OrderID
''''''' .Item("OrderDate").Range.Text = frmOrder.OrderDate
''''''' End With
' Build SQL string for details
strSQL = "SELECT [Address]," & _
"[Erf No]," & _
"[List Price]," & _
"[Sale Price]," & _
"[RPPRStandM2]," & _
"[RPPRResM2]," & _
"[Days On Market]," & _
"[RPPRPercentDrop]" & _
"FROM [qryRPPRDataForCMA]"
' Get details from database and create a table
' in the document
Set rst = New Recordset
rst.Open strSQL, CurrentProject.Connection
With CreateTableFromRecordset(objWord.ActiveDocument.Bookmarks("RPPRdata").Range, rst, True)
' Add rows for subtotal, freight, total
With .Rows.Add
.Cells(1).Range.Text = "Average"
.Cells(4).Range.Text = FormatNumber(frmRpprDataSelected.AvgSalePrice, 0)
.Cells(3).Range.Text = FormatNumber(frmRpprDataSelected.AvgListPrice, 0)
.Cells(7).Range.Text = FormatNumber(frmRpprDataSelected.AvgListDays, 0)
End With
.Range.Font.Size = 8
'Set width works nicely!
.Range.Tables(1).Columns(2).SetWidth CentimetersToPoints(3), wdAdjustNone
.Range.Tables(1).Columns(2).Select
objWord.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
'Other alternative
'.AutoFormat
' Apply formatting
'.AutoFormat wdTableFormatProfessional
'.AutoFitBehavior wdAutoFitContent
' Fix up paragraph alignment
.Range.ParagraphFormat.Alignment = wdAlignParagraphRight
.Columns(1).Select
objWord.Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
objWord.Selection.MoveDown
End With
' We're done
Set objWord = Nothing