Sample Applications Integrating MS-Word

 

The following sample applications are included when you purchase the VB 2010 Tutorial Download Package or the VB 2010 "Extra" Sample Applications from The VB Programmer.

 

1. Generate an MS-Word Document "from Scratch"

This sample application demonstrates how to generate an MS-Word document "from scratch", meaning that the program alone creates the Word document without using a template as a basis. This sample application uses a subset of the Customer table from the "Cust.mdb" database used in several of the other sample applications. It uses Word to generate a customer address and phone number list, sorted by state. The interface for the program, shown below, is rather plain – it just lets the user select options for saving and outputting:

 

 

Assuming the user has selected the "Saving Option" to save to a filename and location of his or her choice, a dialog box appears:

 

 

Assuming the user has selected the "Output Option" to open the resulting file in MS-Word, Word opens the newly created document:

 

 

 

2. Generate a Set of Mailing Lables with MS-Word

 

This sample application demonstrates how to generate a set of mailing labels using a template. Note: When we say "template",  we are NOT referring to a Word "template" in the strictest sense (i.e., an MS-Word ".dot" file) – what we mean by "template" is simply another Word document (".doc" file) that contains the necessary formatting that can be used as a basis for what we want the application to generate. In the case of this application, the "template" is simply a Word .doc file that contains an empty table where the dimensions of that table's cells match those of the Avery 5160 label sheets. The program then copies that template to a work file and fills in the cells of that table with the appropriate data.

 

This application also uses the "Cust.mdb" database. The user interface is very similar to that of the first demo application:

 

 

Screen shot of the mailing label output:

 

 

3. Generate a Set of Form Letters with MS-Word

 

This sample application demonstrates how to generate a set of form letters using a template (again, our concept of a "template" is described above).  In this case, the template is a form letter (a regular ".doc" file)  that uses our own custom "substitution tags" as placeholders for the variable data. A screen shot of the template is shown below:

 

 

Data from the database (once again using "Cust.mdb") is then merged with the template, and one letter for each customer record is produced (substituting the data from the record for the appropriate substitution tag). Note that we prefer NOT to use MS-Word's "Mail Merge" feature, as doing so restricts your application design choices.

 

The user interface is very similar to that of the first two demo applications:

 

 

Screen shot of the form letter output: