Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Merging Data into a Word Document

Status
Not open for further replies.
Feb 6, 2003
48
US
Hi-

I have created VB code that successfully pulls data from my data source and I have created a list view where I can see it. Now I need to put that data into a form I have created. It would work fine if I selected one person at a time, but I need to do print one form for each person in the recordset. When I run it now, all of people show up on one form.

I am using the following to send the data to the form:

"Word.ActiveDocument.Bookmarks("Name").Range.Text = rs!Name"

I have also tried to setup a mail merge and that was not successful either. However, that is not saying much, because I am very new to VB and am not sure that I set up the mail merge correctly.

I am so close to finishing this, any help, suggestions would be greatly appreciated. Thanks
 
You need to set up a loop to move through each record and copy the data
Code:
Do Until Rs.EOF
   Open a new word Document
   Copy the data into the bookmark
   Save and close the Word document with a unique name
   Move to the next record in your recordset
Loop
Close Word

This question has been asked quite recently in other Access forums here (can't remember which one). Try a Keyword search on "Merging to Word" for details on exactly how to accomplish it.

HTH
Lightning
 
Thank you very much for the posting. This form could have 50-75 records in the data set so I was hoping to be able to create new pages within the document, instead of creating a new document for each record. When complete, this form will be deployed to an end user who is not technically savvy, and one 75 page document would be much easier for them to deal with than 75 one page documents.

Could a sequence like this be programmed:

Copy original form,
DO UNTIL rs.eof
Fill in form
New Page
Copy Org. Form

Any ideas on how I might make this work? Thanks again for your help.
 
With the new page approach, you would also need to recreate the bookmark with a unique name on each page and then include the unique name into the loop to ensure the data ended up in the correct bookmark.

I had a similar problem in a recent project and got around the problems by creating the individual documents and a Master document. I created the individual documents and then copied each document into the Master document afterwards, and then deleted the individual documents. This left just the one document. This appraoch meant that I didn't have to worry about continually creating unique bookmarks, but could just re-open the one template for each document.

Maybe not the most elegant solution, but it worked for my project and client.

HTH
Lightning
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top