Results 1 to 4 of 4

Thread: How to add tables into a Word97 document using VB6 and DAO?

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    3

    Question

    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


  2. #2
    Registered User
    Join Date
    Apr 1999
    Location
    Brazil
    Posts
    144

    Lightbulb Suggestion

    Open Word; begin record macro; insert a table (4x5);
    stop record macro; open your new macro.

    Magic! You have a code!

    Jefferson

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    3
    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.

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    3
    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width