Hi,
I want export data from Access 2007 to word 2007 with legacy forms. I created a simple layout, and i copied the code from this author
http://www.techrepublic.com/blog/how...tag=rbxccnbtr1
(the second version to populate all data).
The point is, access data populates the fields into the word fields, but is not making new pages for each record.
The only way that i did to create 170 pages with access data, is only when i use the mail merge function.
Private Sub btnexport2word_Click()
'Print customer slip for current customer.
Dim appWord As Word.Application
Dim doc As Word.Document
Dim db As Database
Dim rst As dao.Recordset
'Avoid error 429, when Word isn't open.
On Error Resume Next
Err.Clear
'Set appWord object variable to running instance of Word.
Set appWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
'If Word isn't open, create a new instance of Word.
Set appWord = New Word.Application
End If
'Populate recordset object.
Set rst = CurrentDb.OpenRecordset("SELECT * from warehouse", dbOpenForwardOnly)
'Cycle through records to fill Word form fields.
Do While Not rst.EOF
Set doc = appWord.Documents.Open("E:\ACCESS DATABASE\warehouse.docx", , True)
With doc
.FormFields("fldprid").Result = rst!prID
.FormFields("flddescription").Result = rst!ProductDescription
.Visible = True
.Activate
rst.MoveNext
End With
Loop
Set doc = Nothing
Set appWord = Nothing
Exit Sub
errHandler:
MsgBox Err.Number & ": " & Err.Description
End Sub
Any ideas?