-
From VB6, I open a Word document and fill it with data from an Access db using Recordsets and DAO. This works fine. The problem is that I don't know how create a Table inside this document. The document ultimately will contain text and tables. Looking for suggestions! Thanks.
Dim RptDb as Database
Dim rsRpt as Recordset
Dim oDoc as Word.Document
Dim strDoc as String
Set oDoc = GetObject("pathname of emptyfile.doc")
...
rsRpt.MoveFirst
Do Until rsRpt.Eof
...
Select Case rsRpt("AnswerType")
Case "Text"
strDoc = ....
oDoc.Application.WordBasic.Insert strDoc
Case "Table"
...
If Not rsTbl.BOF and Not rsTbl.EOF then
'determine number of cols and rows needed
'now create the table, fill it with the
'Access data
Case ....
End Select
rsRpt.MoveNext
Loop
-
Suggestion
Open Word; begin record macro; insert a table (4x5);
stop record macro; open your new macro.
Magic! :) You have a code!
Jefferson
-
I'm not sure that will get me what I need, but I will try it.
The VB app is essentially generating a Report using Word. The Word document must handle various types of data. The text is already in the document and working fine. The app must be able to dynamically create a Table in the Word document that has, say, 2 columns and 3 rows of data (only for this particular Table). This table is then followed by more text. Later, another table must be added to the Report, but this one requires 5 columns and 20 rows. Etc... There will be about 25 tables included in the final document/report.
I was thinking that Bookmarks and Ranges might be what I need, but I don't know how to use them here.
-
I used the macro code to create the table in the Word document. Now, all the text that follows the table is entered as part of the table too!!! Any idea on how to tell it the table has ended and that the following is just regular text?