Populate Word Table

T

Ted

Would someone please tell me how to populate a Word 5 Column Table with data
retrieved from a Sql Server via ADODB connection. I would like the data to
look like a Report in Word. I know how to make the connection however I
don't know how to format it nicely in Word.
thanks,
Ted
 
M

Malcolm Smith

Ted

It depends on how big the table is going to be. For some of my reports
which I make I don't use tables but, rather, I use Tabs because using
tables is slower and make for fatter Word documents.

If you know how to make the Connection object then I guess that you know
how to make the RecordSet object.

So, I am not sure what you want to do next. But if you this regularly
then may I suggest that you set up a template and then create your data
report in there and then you know how it's going to look.

To populate the table you can put the selection into the first column and
the second row of the table (say it's table one) as I am assuming that row
one is for the title and then something like:


oDoc.Tables(1).Cell(2,1).range.select
Do while not oRS.EOF
selection.typetext ors("Col_01")
selection.typetext vbtab ' or whatever it is to go to the next cell

' and so on
oRS.MoveNext
loop

Something like that. But if you have the table setup in a template
first then you know how it's going to look and you don't need to change
the code each time you want to change the layout.

Hope this is a help.
- Malc
 
A

Alex Ivanov

Ted,
Create an autotext entry containing a single row of your table with
bookmarks in each field and insert that autotext for every record in the
recordset. Please look at this sample. It uses Access as a source, but will
work with any ADODB recordsets if you made proper adjustments.
http://www.aleksoft.net/samples/TestReport.zip
 

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

Top