Home | Careers | IT Counseling | IT Jobs | IT Resources

 

 

 
About Us | Advertise | Feedback | Contact Us | Bookmark this page now|
Have any doubts regarding how to Search IT Training Courses?...Click here for Quick Search Tips Search IT Courses
Have any doubts regarding Keyword Search?...Click here for Quick Search Tips keyword
Have any doubts regarding Institutes Search?...Click here for Quick Search Tips institutes
Have any doubts regarding Specialization Search?...Click here for Quick Search Tips specialization
Have any doubts regarding Fees Search?...Click here for Quick Search Tips fees
to
Have any doubts regarding Duration Search?...Click here for Quick Search Tips duration

IT dart Tips

Which IT course ?

Venture Capital

Online Education

Exams Required for US of A

Overview of Admission Process

Test Preparation

Financial Aid

TOEFEL Examination

Cool Interview Tips

Skill Check

Resume

GRE Examination

GMAT Examination


IT dart News Letter
Get ITdart.com weekly headlines before it's published on our site! Subscribe and receive the articles delivered to your inbox!

Using Word to generate form letters programmatically

Using Word to generate form letters programmatically
As discussed earlier, Word can be used as a powerful report writer. To illustrate this, let's go through the steps and code required to use
Word as a form letter generator.

Assume that your program is being coded in Visual FoxPro (although this could have been coded in any other language that supports OLE automation). You have a table consisting of Name, Sex, Salary and Designation fields and want to print a letter as follows:

Date: Today's Date
Dear Mr/Ms Name
This is to inform you that you have been appointed as
Designation and your gross salary is Rs. Salary
The items marked in red are actual fields. The items marked in blue are derived from some other values.

Now this letter could also be generated by directly using Word's mail-merge feature. However, the mail-merge feature has some disadvantages in that it may be difficult to handle at the end-user level. Mail-merge also requires the data source to be hard-coded.

Here is how you go about building this module.

Step 1: Creating the document with form fields.

Start Word manually (not invoked from a program).
Type the contents of the report as required.
To insert form fields, say, the Date field, first type the word "Date:" as usual.
Right click on the toolbars and choose the Forms toolbar.
A Text Form Field button is available on the Forms toolbar. Position your cursor in front of the word "Date:" and click this button
This will insert a small grey-coloured patch at the cursor position. Double click the grey patch to set the properties of the text form field.
This following dialog box will appear. Set the values for the Date field as shown.

Similarly, do this for remaining fields by specifying values as follows. Choose the formatting as required.

Bookmark
Type

frmDate
Date

frmName
Text

frmDesignation
Text

frmSalary
Number

Step 2: Save this as a template.

Save this document using the Save As option. Use the Document Template file type. Let us assume you save it as "C:\DEMO.DOT"

Step 3: Invoke Word from within your program.

Assuming Word is being invoked from Visual FoxPro, the code to do so is as follows:

* This creates a reference to the Word application
wrd = createobject('word.application')
* Normally you would not want to make it visible
* but for demo purposes you can view the Word file
wrd.visible = .t.
* Open the table (Sample) and process each row
Use Sample
scan
* Add a new document based upon the template
doc = wrd.documents.add("C:\DEMO.DOT")
* Get reference to the formfields collection
flds = doc.formfields
The formfields available in the document are available as a collection of the activedocument object.

Step 4: Fill the correct values in all the fields.

The formfields collection is now incorporated in the variable flds. You can fill values by assigning the correct value to the result property of each field.

flds("frmDate").result = date()
flds("frmName").result = sample.name
* similarly, stuff values in all the other form fields
Step 5: Save this document.

doc.saveas "Some file name"

This step is optional. If you do not want to store a file copy, you can omit this step.

Step 6: Print it using Word's print features.

Printing it is simple.

doc.printout
* Repeat this code for each record
endscan
Step 7: If required, a print preview can also be incorporated.

If you want a print preview, you will have to make the Word instance visible.

* If a print preview is wanted
* just make Word visible and use the command
wrd.visible = .t.
doc.printpriview

One Click Courses

Advanced Certiflcate in Java Application Development

Advanced Cisco Router Conflguration

Advanced Course in Object Oriented Programming (Coop)

C#

C# with ASP.Net

CAD/ CAM

Certfication in Unix, C, C++ (CUCC)

Certificate in Advanced System Programming

Certificate in Java & E-commerce (CJEC)

EI -Strategiest

Object Oriented Developer and Designer

Specialization in 3D Graphics & Animation

Wap@Asset


Firewalls: What To Block

Windows System Architecture (WSA)

Operating System (OS)

Data Access Technologies

Functional menu-level blocking

Data Access Methodologies

ODBC Architecture

Learn Java from the ground up

Internet Security

The Day I Learnt JavaScript



ITdart Updates:
Computer Security | Computer Services | CRM | Database | E Commerce | Graphic & Design | Internet | Java | Knowledge Management | Linux | Online Marketing | Open Source | Operating System | Robotics | Semi Conductors | Software Downloads | Virus Info | WAP & 3G | Web Development | XML and Metadata
Home | Careers | IT Counseling | IT Jobs | IT Resources

© Copyright 1999-2000 ITdart.com. All rights reserved.
All brands are Trade Marks of Respective owners. Disclaimer    Legal    Privacy Policy