Results 1 to 2 of 2

Thread: inserting records into a word document

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2003
    Posts
    4

    inserting records into a word document

    I have a standard word document with bookmarks and a vb6 form where the user selects multiple names from a list box.
    what i want to do is when the user selects three names from the listbox. I want to be able to take the three names query the access database open the word document and populate the necessary filds in the appropriate bookmark.

    I have a standard letter which is saved in test .doc with the necessary bookmarks. and when the user selects four records from a listbox, I want to open this document and give the user the user the ability to view and print the letter for each record selected. the problem with opening and saving one document each for each records is that the user will have to open twenty documents if they select twenty records. that's why I want to use one document to show all of the letters that will be printed for each record selected. in other words if I wnat to send twenty letters to twenty people all of them with the same content except for the inserted records, I want to see all of my letters in one document. this is what i have so far

    openDB (sqlstring)
    If rsObj.RecordCount = 0 Then
    Exit Function
    End If

    Set objWord = CreateObject("Word.Application")
    While Not rsObj.EOF
    With objWord
    .Visible = True
    .Documents.Open (strDocPath)
    .ActiveDocument.Bookmarks("name").Select
    .Selection.Text = rsObj.Fields("name")
    .ActiveDocument.Bookmarks.Add Name:="name"
    Range = .Selection.Range
    End With
    rsObj.MoveNext
    Wend

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Try this - you'll need to extract the database to the root of your C:\ drive or change the code to point to this...
    Attached Files Attached Files

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

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