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
Try this - you'll need to extract the database to the root of your C:\ drive or change the code to point to this...
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