Basic Macros


A basic macro macro that talks to ODBC is:
//----------------------------------------------------------
// Basic WordPerfect ODBC macro
// © Geoff Lane - 1997
//----------------------------------------------------------
  // Tell WordPerfect we're going to use ODBC
ImportSetSource (SourceType: ODBC!)

  // Select the way the data will display in WordPerfect,
  // we have a choice of MergeData!, TabbedText!, or WPTable!
ImportSetDestination (DestinationType: WPTable!)

  // Tell WordPerfect if we wish to include the column headings
  // We can select On! to include headings or Off! to exclude them.
ImportSetIncludeNames (State: On!)

  // Tell WordPerfect which ODDBC data source to use
ImportSetDataSource (Source: "MyData")

  // Pass the SQL Query to WordPerfect
ImportSetSQLQuery (SQLQuery: MyQuery)

  // Pass the request to ODBC
ImportDoImport()

The variable (MyQuery) contains the SQL statement. You should define this before before the call the ImportSetSQLQuery.

Example:

The following macro statements create a table called "Contact" in the data source "MyData". Note the use of NOT NULL to ensure that LastName always contains a value.

//----------------------------------------------------------
// Example WordPerfect ODBC macro
// © Geoff Lane - 1997
//----------------------------------------------------------
  //Build the SQL statement
MyQuery := "CREATE TABLE Contact ("+
     "ID COUNTER CONSTRAINT ContactPrimaryKey PRIMARY KEY, "+
     "FirstName CHAR(16), "+
     "LastName CHAR(16) NOT NULL, "+
     "Street CHAR(32), "+
     "Address1 CHAR(32), "+
     "Address2 CHAR(32), "+
     "City CHAR(32), "+
     "County CHAR(20), " +
     "PostCode CHAR(16), "+
     "Country CHAR(20), "+
     "BusinessTelNo CHAR(16), "+
     "HomeTelNo CHAR(16), "+
     "FaxNo CHAR(16), "+
     "email CHAR(64))"

  //Now process as in the basic macro
ImportSetSource (SourceType: ODBC!)
ImportSetDestination (DestinationType: WPTable!)
ImportSetIncludeNames (State: On!)
ImportSetDataSource (Source: "MyData")
ImportSetSQLQuery (SQLQuery: MyQuery)
ImportDoImport()
[Return to Macros Page]