Try This 

How to Create Mail Merge Set the Transaction object for the DataWindow control 
and retrieve data

 **************************************************/

 dw_mail.SetTransObject(SQLCA)

 dw_mail.Retrieve()

The following script generates and prints the form letters:

OLEObject contact_ltr

 integer result, n

 string ls_name, ls_addr

 /***************************************************

 Allocate memory for the OLEObject variable

 ***************************************************/

 contact_ltr = CREATE oleObject

 /***************************************************

 Connect to the server and check for errors

 ***************************************************/

 result = &

    contact_ltr.ConnectToNewObject("word.application")

 IF result <> 0 THEN

    DESTROY contact_ltr

    MessageBox("OLE Error", &

       "Unable to connect to Microsoft Word. " &

       + "Code: " &

       + String(result))

       RETURN

 END IF

 /***************************************************

 For each row in the DataWindow, send customer

 data to Word and print a letter

 ***************************************************/

 FOR n = 1 to dw_mail.RowCount()

 /************************************************

    Open the document that has been prepared with

    bookmarks

 ************************************************/

    contact_ltr.documents.open("c:\pb8\contact.doc")

 /************************************************

    Build a string of the first and last name and

    insert it into Word at the name1 and name2

    bookmarks

 ************************************************/

    ls_name = dw_mail.GetItemString(n, "first_name")&

    + " " + dw_mail.GetItemString(n, "last_name")

    contact_ltr.Selection.goto("name1")

    contact_ltr.Selection.typetext(ls_name)

    contact_ltr.Selection.goto("name2")

    contact_ltr.Selection.typetext(ls_name)

 

 /************************************************

    Build a string of the address and insert it into

    Word at the address1 bookmark

 ************************************************/

    ls_addr = dw_mail.GetItemString(n, "street") &

       + "~r~n" &

       + dw_mail.GetItemString(n, "city") &

       + ", " &

       + dw_mail.GetItemString(n, "state") &

       + " " &

       + dw_mail.GetItemString(n, "zip")

    contact_ltr.Selection.goto("address1")

    contact_ltr.Selection.typetext(ls_addr)

 /************************************************

    Insert the letter text at the body bookmark

 ***********************************************/

    contact_ltr.Selection.goto("body")

    contact_ltr.Selection.typetext(mle_body.Text)

 /************************************************

    Print the letter

 ************************************************/

    contact_ltr.Application.printout()

 /************************************************

    Close the document without saving

 ************************************************/

    contact_ltr.Documents.close

    contact_ltr.quit()

 NEXT

 /***************************************************

 Disconnect from the server and release the memory for the OLEObject variable

 ***************************************************/

 contact_ltr.DisconnectObject()

 DESTROY contact_ltr

 



--- On Fri, 8/29/08, R. Azhar <[EMAIL PROTECTED]> wrote:
From: R. Azhar <[EMAIL PROTECTED]>
Subject: [indopb] Buat Mail Merge dengan Word
To: [email protected]
Date: Friday, August 29, 2008, 5:57 AM





Saya coba buat mail merge yang nantinya akan di print berdasarkan 
data-data yang ada dengan oleobject. Saya belum bisa bagaimana 
mengeluarkan output atau menyimpan file yang telah berisi data-data yang kita 
masukkan
berdasarkan template yang sudah kita buat dalam sebuah datawindow menjadi 
sebuah file baru.
Thanks






      




      

Kirim email ke