How to insert a database field into an MS WORD document and print document from an application

Posted on 2008-02-06
Medium Priority
Last Modified: 2010-04-21
I have to print a questionnaire that is in MS WORD format to send to many establishments.  The  establishment's name and address are in a database and are indexed by a unique id field.  I want to develop a procedure that will insert the unique id field then print the questionnaire for each establishment that is in my database.  

Can this be done using an MS-WORD macro?  I have developed quite a few database applications in VB6  but has never done anything involving the MS Office suite, so can someone please give me an overview of how this is achieved or point me to some resource that explains it.  Thanks.
Question by:desmondg
  • 2
  • 2
LVL 77

Expert Comment

ID: 20835154
You probably don't need a macro. You can use mail merge. There is a wizard for it via the menu (Tools/Letters and Mailings, Mail Merge...)

Come back here if you get stuck
LVL 25

Expert Comment

by:Lee Savidge
ID: 20835319

If you don't do mail merge which, by the way, is the  best option, then I would investigate setting up a document that contains the letter structure you want but where the variable fields like name and address are entered as Bookmarks. Then you can write a VB app that queries the database and loops through the recordset and replaces each bookmark with the correct information. You would need to refernce the MS Word application in your VB program and then create a new Word object. Ther are plenty of examples of using bookmarks for automating Word to do mail merge type functions.

Here is one example: http://www.xtremevbtalk.com/showthread.php?t=38933
Here is a list of URLs: http://blogs.msdn.com/pranavwagh/pages/535020.aspx

The bookmarks is a way that I have used in the past and it works well. A tip when you Automate Word... Remember the DisplayAlerts function.




Author Comment

ID: 20835592
I am not sure that mail merge is what I want since the intention is that the establishment should remain anonymous.  The questionnaire will be hand delivered.  No name nor address information should be printed on the questionnaire, only the ID field.  The delivered will know where to deliver the questionnaire because that person will have access to the database.

I am looking at the bookmark suggestion.
LVL 77

Accepted Solution

GrahamSkan earned 1000 total points
ID: 20835729
You can choose which fields are to be shown on the document. If you only need the ID, just insert that field.

Author Closing Comment

ID: 31428619
Thanks GrahamSkan.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

592 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question