Creating Tables

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
 
D

Doug Robbins - Word MVP

This

objWord.Selection.InsertBreak (wdPageBreak)

is telling Word to insert the break at the location of the Selection,
rather than at the end of the document.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top