Connection Information

To perform the requested action, WordPress needs to access your web server. Please enter your FTP credentials to proceed. If you do not remember your credentials, you should contact your web host.

Connection Type

Example: generating form letters using OLE – PB Docs 125 – PowerBuilder Library

Example: generating form letters using OLE – PB Docs 125

Example: generating form letters using OLE

This example takes names and addresses from a DataWindow object
and letter body from a MultiLineEdit and creates and prints letters
in Microsoft Word using VBA scripting.

proc.png To set up the form letter example:

  1. Create a Word document called CONTACT.DOC with
    four bookmarks and save the file in your PowerBuilder directory.

    These are the bookmarks:

    • name1 – for
      the name in the return address

    • name2 – for the name in the salutation

    • address1 – for the street, city, state,
      and zip in the return address

    • body – for the body of the letter

    The letter should have the following content:

    You could enhance the letter with a company and a signature
    logo. The important items are the names and placement of the bookmarks.

  2. In PowerBuilder, define a DataWindow object called d_maillist that
    has the following columns:

    • id

    • first_name

    • last_name

    • street

    • city

    • state

    • zip

    You can turn on Prompt for Criteria in the DataWindow object
    so the user can specify the customers who will receive the letters.

  3. Define a window that includes a DataWindow control
    called dw_mail, a MultiLineEdit called mle_body,
    and a CommandButton or PictureButton:

    oleap03.gif
  4. Assign the DataWindow object d_maillist to
    the DataWindow control dw_mail.

  5. Write a script for the window’s Open
    event that connects to the database and retrieves data for the DataWindow
    object. The following code connects to a SQL Anywhere database.
    (When the window is part of a larger application, the connection
    is typically done by the application Open script.)

  6. Write the script for the Generate Letters button
    (the script is shown below).

    The script does all the work, performing the following tasks:

    • Creates the OLEObject variable

    • Connects to the server (word.application)

    • For each row in the DataWindow object, generates
      a letter

      To do so, it uses VBA statements to perform the tasks in Table 19-5.

      Table 19-5: Script tasks

      VBA statements

      Task

      open

      Opens the document with the bookmarks

      goto and typetext

      Extracts the name and address information
      from a row in the DataWindow object and inserts it into the appropriate
      places in the letter

      goto and typetext

      Inserts the text the user types in mle_body into the
      letter

      printout

      Prints the letter

      close

      Closes the letter document without saving
      it

    • Disconnects from the server

    • Destroys the OLEObject variable

  7. Write a script for the Close button. All it needs
    is one command:

Script for generating form letters

The following script generates and prints the form letters:

Running the example

To run the example, write a script for the Application object
that opens the window or use the Run/Preview button on
the PowerBar.

When the application opens the window, the user can specify
retrieval criteria to select the customers who will receive letters.
After entering text in the MultiLineEdit for the letter body, the
user can click on the Generate Letters button to print letters for
the listed customers.


Document get from Powerbuilder help
Thank you for watching.
Was this article helpful?
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x