Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Inserting ADO recordset into Word Table

250 views
Skip to first unread message

Loraine

unread,
May 16, 2000, 3:00:00 AM5/16/00
to
I have an "ADODB.RecordSet" object called MyAdoRecSet.
I want to insert the recordset into a Word table having the same
number of columns as there are fields in the recordset.
My code inserts the data field-by-field and record-by-record
into the cells of the table (see below - written in VFP6).
This is slow. Is there a faster way to do this?

MyAdoRecSet.MoveFirst
WITH MyWordTable
FOR lnRow = lnFirstRow TO lnRecCount
FOR lnCol = 1 to lnFieldCount
.Cell(lnRow,lnCol).Range.InsertAfter
(MyAdoRecSet.Fields(lnCol - 1).Value)
ENDFOR
MyAdoRecSet.MoveNext
ENDFOR
ENDWITH

TIA,
Loraine


* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!


Dave Rado

unread,
May 18, 2000, 3:00:00 AM5/18/00
to
Yes - it's slow because you're asking Word to recalculate the row and column
index of the curent cell every single time.

Use the Next property of the Cell to go from one cell to the next. Also,
I'd use the Text property rather than InsertAfter.

Dim oCell As Cell
Set oCell = MyWordTable.Cell(1,1)
For lnRow = lnFirstRow To lnRecCount
For lnCol = 1 to lnFieldCount
oCell.Text = _
(MyAdoRecSet.Fields(lnCol - 1).Value)
Set oCell = oCell.Next
Next nCol
Next lnRow

Regards

Dave

Loraine <loraines...@hdsinc.net.invalid> wrote in message
news:1351beaf...@usw-ex0103-024.remarq.com...

Loraine

unread,
May 19, 2000, 3:00:00 AM5/19/00
to
Thanks Dave, I tried your suggestion but didn't find any
measurable speed difference - that may be because my recordsets
are not very big? Just a note that a range expression needs to
be added to the one statement (oCell.RANGE.text = "something").

Is there is a way to grab a whole recordset record at one time
and replace a whole row in a Word table, rather than field-by-
field and cell-by-cell?

Thx again,

Dave Rado

unread,
May 19, 2000, 3:00:00 AM5/19/00
to
Hi Lorraine

You might get a better response if you post to
microsoft.public.word.word97vba.

Regards

Dave

Loraine <loraines...@hdsinc.net.invalid> wrote in message

news:267e18ac...@usw-ex0103-024.remarq.com...

John McGhie [MVP - Word]

unread,
May 20, 2000, 3:00:00 AM5/20/00
to
In microsoft.public.word.tables on Fri, 19 May 2000 08:21:04 -0700, Loraine
<loraines...@hdsinc.net.invalid> wrote:

> Thanks Dave, I tried your suggestion but didn't find any
> measurable speed difference - that may be because my recordsets
> are not very big? Just a note that a range expression needs to
> be added to the one statement (oCell.RANGE.text = "something").
>
> Is there is a way to grab a whole recordset record at one time
> and replace a whole row in a Word table, rather than field-by-
> field and cell-by-cell?

Lorraine:

I would be sorely tempted to send the whole lot across as tab-delimited
text, then use Word's ConvertToTable Method to make the table after you have
sent all the data across.

Obviously someone at Microsoft had problems with this, because it appears
ConvertToTable has been re-coded for efficiency. It's so blindingly fast
that I smell some inline assembler in there somewhere :-)

Note: You may find a big speed improvement if you code the module in VBA in
a Word template and simply call it from FoxPro, rather than having to
support all the cross-chatting across the OLE interface, which is
notoriously slow.

Look up ConvertToTable Method in the VBA help.

Cheers.

Please post follow-up questions to the newsgroup so that all may follow the thread.

John McGhie <jo...@mcghie-information.com.au>
Consultant Technical Writer
Microsoft MVP (Word)
Sydney, Australia (GMT +10 hrs) +61 (04) 1209 1410

Loraine

unread,
May 22, 2000, 3:00:00 AM5/22/00
to
Putting the code into Word macro sounds like a good alternative,
but I need to create the ADO recordset from a temporary Visual
FoxPro table. I would like to create the ADO recordset from the
FoxPro side - how then do I reference that recordset from my
Word macro?

Dave Rado

unread,
May 22, 2000, 3:00:00 AM5/22/00
to
In your VBA project you can set a reference to ADO. I'm not sure about the
rest of the code though - you'll get more help if you post to the VBA
newsgroup. But John's suggestion of writing the text into the word document
as tab-delimeted text rather than into a table, and then using the
ConvertToTable method at the end, should speed up your code significantly
even without using a Word macro.

Regards

Dave

Loraine <loraines...@hdsinc.net.invalid> wrote in message

news:17a55ce8...@usw-ex0103-019.remarq.com...

0 new messages