Results 1 to 5 of 5
  1. #1
    Lounger
    Join Date
    Sep 2004
    Location
    Nashville, Tennessee, USA
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Filling a Word Table from VB.NET (Word 2003)

    I am attempting to fill a table in Word with the results of a SQL Stored Procedure called from a VB.NET program. I am using a Dataset (could use a DataReader, I think) but can not determine how to address moving the data to the Word table. I want to do this in one move as writing it field by field is taking hours.

    Bob

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Filling a Word Table from VB.NET (Word 2003)

    Is your Word table simply a replica of your recordset and are your fields short and free of line breaks? If so, you might be able to do it in three steps:

    (1) Extract the entire recordset into string that has useful delimiters between your records and fields;
    (2) insert the big string into the document; and
    (3) Convert the inserted text to a table.

    For #1, ADO has a handy method named getString() where you would use vbTab as your column delimiter and vbCrLf as your row delimiter.

  3. #3
    Lounger
    Join Date
    Sep 2004
    Location
    Nashville, Tennessee, USA
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Filling a Word Table from VB.NET (Word 2003)

    Thank you for your reply.
    I have attempted to process the table as you suggested by writing each record in a string with vbTab between fields then using convert to table with tab delimiters but for some reason there were some records that lost a tab and this skewed all the following records by one or more field. I will go back and try to determine why the delimiters were lost and try this tact again. Maybe using paragraph delimiters will work better. I will try using the getString() method, thanks.

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Filling a Word Table from VB.NET (Word 2003)

    <P ID="edit" class=small>(Edited by jscher2000 on 18-Jul-06 23:00. Replaced attachment)</P>A few months ago I read some articles on the Microsoft Knowledgebase on how to format a text string and place it on the clipboard as HTML. As the getString method can accept HTML tags as well as vbConstants, another idea might be to format the string as an HTML table, then coax that into the clipboard and paste it into Word. Word seems to know how to automatically convert HTML tables to Word tables.

    The attached code snippet might help. The code uses the clipboard to insert a list of attachments into the message body. Apologies if it doesn't compile or run as is, but it is one module out of a project and I can't recall any dependencies it might have on other bits and pieces.
    Attached Files Attached Files

  5. #5
    Lounger
    Join Date
    Sep 2004
    Location
    Nashville, Tennessee, USA
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Filling a Word Table from VB.NET (Word 2003)

    The piece I was missing in creating a table from the input text was a vbCrLf at the end of the row, since I told the macro how many columns in the table I overlooked that little part. Now that I'm adding the ending mark it seems to work fine. [creating a document in seconds that takes 20 minutes in Access and was taking hours one record at a time using VB.NET]

    I will take a look at the HTML/clipboard code as I always like to have several tools in my kit.

    Thank you.

Posting Permissions

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