inserting table and data in word document

J

Jesper F

I need to insert a table in a word document, that I'm opening up with
late binding.

Currently I simply loop through the Access recordset and create a text
chunk with the fields-to-be seperated by semicolons. (iCount is the
row count and iFieldsCount is the column count).

I then use:

oword.Selection.MoveDown Unit:=WD_Line, Count:=iCount + 1,
Extend:=WD_Extend
oword.Selection.ConvertToTable Separator:=WD_SeparateByCommas,
NumColumns:=iFieldsCount, NumRows:=iCount,
AutoFitBehavior:=WD_AutoFitContent

to select the text chunk and convert it to a table.
(oword is my word object).

However this fails sometimes because I don't know the length of the
text chunk and thus don't know how much text to select before
attempting to convert it to a table.

Can I instead create a table and start in cell no. 1 and walk through
that table and simultaniously walk through the recordset and insert
values in the cells?

Many thanks.
 
M

Mr B

Jasper F,

I don't have any code to share with you but here is an option you might want
to consider and evaluate:

You might try using the "DoCmd.OutputTo " method and export your table to
Excel format and then programatically insert the new Excel document into your
Word document.

I know this requires a mid step but it just might give you the desired
results.

Good luck with your project.
 
P

Piet Linden

I would check the Word NG for this. I'm sure Macropod could sort it
out... One way of doing it is to insert the table and then append rows
to the bottom of it, inserting your database data as you go.
 
J

Jesper F

Thanks both of you, I'll try the Word NG.

Automation of word doesn't seem to be so widespread.
 

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