E
Er
Hi,
I am trying to read from a database, and each record should appear in its
own table on its own page in a Word document (this is in VB6, not VBA),
ending up with n pages for n records.
The problem with my code is that all tables end up at the end of the
document, all on the same page (last one), with n number of blank pages
before it. All records end up in the first table, not in each table (there
seems to be one table with n times 6 rows in it).
Any help would be appreciated.
Erwin
-------------------------------------------------------------------------------------------------------
Here's the code I have so far:
Dim objWord As Word.Application
Dim objWordDoc As Word.Document
Dim objTable As Word.Table
Set objWord = CreateObject("Word.Application")
Set objWordDoc = objWord.Documents.Add(, , 0)
Do While rs.EOF = False
Set objTable =
objWordDoc.Tables.Add(objWordDoc.Range(objWordDoc.Range.End - 1,
objWordDoc.Range.End - 1), 6, 2)
objTable.Cell(1, 1).Range.InsertAfter "Agency/Program"
objTable.Cell(1, 2).Range.InsertAfter rsContacts("v1")
objTable.Cell(2, 1).Range.InsertAfter "Contact Name"
objTable.Cell(2, 2).Range.InsertAfter rsContacts("v2")
objWord.Selection.InsertBreak (wdPageBreak)
rsContacts.MoveNext
Loop
rsContacts.Close
objWordDoc.SaveAs "C:\hello5.doc"
objWordDoc.Close
objWord.Quit
I am trying to read from a database, and each record should appear in its
own table on its own page in a Word document (this is in VB6, not VBA),
ending up with n pages for n records.
The problem with my code is that all tables end up at the end of the
document, all on the same page (last one), with n number of blank pages
before it. All records end up in the first table, not in each table (there
seems to be one table with n times 6 rows in it).
Any help would be appreciated.
Erwin
-------------------------------------------------------------------------------------------------------
Here's the code I have so far:
Dim objWord As Word.Application
Dim objWordDoc As Word.Document
Dim objTable As Word.Table
Set objWord = CreateObject("Word.Application")
Set objWordDoc = objWord.Documents.Add(, , 0)
Do While rs.EOF = False
Set objTable =
objWordDoc.Tables.Add(objWordDoc.Range(objWordDoc.Range.End - 1,
objWordDoc.Range.End - 1), 6, 2)
objTable.Cell(1, 1).Range.InsertAfter "Agency/Program"
objTable.Cell(1, 2).Range.InsertAfter rsContacts("v1")
objTable.Cell(2, 1).Range.InsertAfter "Contact Name"
objTable.Cell(2, 2).Range.InsertAfter rsContacts("v2")
objWord.Selection.InsertBreak (wdPageBreak)
rsContacts.MoveNext
Loop
rsContacts.Close
objWordDoc.SaveAs "C:\hello5.doc"
objWordDoc.Close
objWord.Quit