Forms, Word and Document Variables

From: Mark <markg_at_mymail.co.uk>
Date: 16 Jul 2002 02:25:09 -0700
Message-ID: <ddb31653.0207160125.503db09e_at_posting.google.com>



Hi,

I have an application which is trying to read a document variable from Word.
Below is an example of a procedure which opens Word, creates a document variable then tries to read the contents of it. It always fails on retrieving the document variable and i get an ORA-305500.

Using Forms6i on Windows 2000 using Word 2000 (although Word 98 should work i think).

The VBA equivalent for writing and reading the document variables are as follows:

ActiveDocument.Variables.Add Name:="MyVar", Value:="12"

ActiveDocument.Variables("MyVar").Value

Any thoughts welcome.


DECLARE

  • Declare the OLE objects MyApplication OLE2.OBJ_TYPE; MyDocuments OLE2.OBJ_TYPE; MyDocument OLE2.OBJ_TYPE; [Quoted]
  • Declare handle to the OLE argument list args OLE2.LIST_TYPE; var varchar2(100);

 BEGIN            

  • Create the Word.Application object and make Word visible
  • by setting the 'Visible' property to true, by default it is invisible. MyApplication:=OLE2.CREATE_OBJ('Word.Application');

  OLE2.SET_PROPERTY(MyApplication, 'Visible', 'True'); -- Comment this line to hide the application.

  • get a handle on Documents collection MyDocuments:=OLE2.GET_OBJ_PROPERTY(MyApplication, 'Documents');
  • Open a new document MyDocument :=OLE2.INVOKE_OBJ(MyDocuments,'Add'); OLE2.DESTROY_ARGLIST(args);

message('Adding Document Variable');

  • Create a document variable MyVar and populate with the value 12 args:=OLE2.CREATE_ARGLIST; OLE2.ADD_ARG(args, 'MyVar'); OLE2.ADD_ARG(args, '12'); OLE2.INVOKE(MyDocument,'Variables.Add',args); OLE2.DESTROY_ARGLIST(args);

message('Reading Document Variable');

  • Read the document variable and display on Forms message line args:=OLE2.CREATE_ARGLIST; OLE2.ADD_ARG(args, 'MyVar'); var:=OLE2.INVOKE_CHAR(MyDocument,'Variables',args); message(var); OLE2.DESTROY_ARGLIST(args);
  • Release the OLE objects OLE2.INVOKE(MyDocument,'Close'); OLE2.RELEASE_OBJ(MyDocument); OLE2.RELEASE_OBJ(MyDocuments); OLE2.RELEASE_OBJ(MyApplication);

exception

         when others then          

     message(sqlerrm||sqlcode);
     OLE2.DESTROY_ARGLIST(args);
     OLE2.INVOKE(MyDocument,'Close'); 
    -- Release the OLE objects
     OLE2.RELEASE_OBJ(MyDocument);
     OLE2.RELEASE_OBJ(MyDocuments);
     OLE2.RELEASE_OBJ(MyApplication);

END;


M Received on Tue Jul 16 2002 - 11:25:09 CEST

Original text of this message