Questions

Answer for:

Word document linked to Access

Message 5 of 6

View entire thread
+
0 Votes

Dynamically generate ms word document using vba access 2007.

There are many ways to approach this
' problem. I usually begin with a word
' template containing the structure of
' the table I want to populate. Then
' open the template from vba in excel
' and begin inserting table records.

Set wdApp = CreateObject("Word.Application")
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Add("Bill.dot")
Set wdTbl = wdDoc.Tables(1) ' containing table

' I use a function to actually populate
' the rows passing it the table id name
' and row data.

Set wdInTbl = wdTbl.Tables(2) ' table in a table

SetTableRow wdInTbl, idx, prevDate & "|" & _
prevJob & "|" & _
Format(prevTime, decFmt) & "|" & _
prevRate & "|" & _
Format(prevAmount, dolFmt)

Sub SetTableRow(tbl As Word.Table, row As Integer, lbl As String)

http://visualbasic.ittoolbox.com/groups/technical-functional/vb-vba-l/dynamically-generate-ms-word-document-using-vba-access-2007-2190479#

Please post back if you have any more problems or questions.