ACC2: How to Programmatically Embed or Link an Object in a Form

ID: Q114214


The information in this article applies to:


SUMMARY

Moderate: Requires basic macro, coding, and interoperability skills.

This article describes how to programmatically embed or link an object in an OLE object field on a form using the object frame properties in Microsoft Access version 2.0.


MORE INFORMATION

You can set the object frame Action property at run time to perform a number of operations on an object frame. These operations include the ability to embed and link objects in an object frame, as well as other operations for programmatic access to OLE functionality.

There are other object frame properties that need to be set as prerequisites to setting the Action property. The properties that need to be set are determined by the type of OLE object you are working with and the type of action, using the Action property, you want to perform.

NOTE: The constants for use by the Action property are defined in the CONSTANT.TXT file, which is included with Microsoft Access. To use the constants in your code, you must either declare them yourself or copy them from the CONSTANT.TXT file and paste them into the Declarations section of your Access Basic module.

Linking an OLE Object

To link an object in an object frame on a form, first set the following properties:
Once you set these properties, you can set the Action property to OLE_CREATE_LINK to link the object in the object frame.

The following sample code demonstrates how to programmatically link a range of cells from a Microsoft Excel spreadsheet to an OLE object field named Sales Totals bound to an object frame with the same name on a form:

   ' Specify what kind of object can appear in the field.
   [Sales Totals].OLETypeAllowed = OLE_LINKED


   ' Specify the file to be linked.
   [Sales Totals].SourceDoc = "C:\EXCEL\SALES.XLS"


   ' Specify the (optional) cell range to link to.
   [Sales Totals].SourceItem = "R1C1:R5C5"


   ' Create the linked object.
   [Sales Totals].Action = OLE_CREATE_LINK 

Embedding an OLE Object

To embed an object in an object frame on a form, first set the following properties:
Once you set these properties, you can set the Action property to OLE_CREATE_EMBED to create an embedded object with a copy of the information in the source document file.

The following sample code demonstrates how to embed a Word for Windows document in an OLE object field named Word Documents bound to an object frame with the same name on a form:

   ' Specify what kind of object can appear in the field.
   [Word Documents].OLETypeAllowed = OLE_EMBEDDED


   ' Specify the file containing the information to embed.
   [Word Documents].SourceDoc = "C:\WINWORD\JONES.DOC"


   ' Create the embedded object.
   [Word Documents].Action = OLE_CREATE_EMBED 

Creating an Empty Embedded Object

To create an empty embedded object in an object frame, first set the following properties:
Once you set these properties, you can set the Action property to OLE_CREATE_EMBED to create an empty embedded object of the type specified in the Class property. Then, set the Action property again to invoke the application for that object.

The following sample code demonstrates how to programmatically create new Word for Windows documents in an OLE object field named Word Documents bound to an object frame with the same name on a form:

   ' Specify what kind of object can appear in the field.
   [Word Documents].Class = "Word.Document"


   ' Specify what kind of object can appear in the field.
   [Word Documents].OLETypeAllowed = OLE_EMBEDDED


   ' Create the embedded object.
   [Word Documents].Action = OLE_CREATE_EMBED


   ' Invoke Word for Windows to edit the empty embedded object.
   [Word Documents].Action = OLE_ACTIVATE 


REFERENCES

Microsoft Access "Building Applications," version 2.0, Chapter 13, "Communication With Other Applications," pages 295-297

For more information about the Action property, search for "Action," and then "Action Property" using the Microsoft Access Help menu.

Additional query words: automation insert


Keywords          : IntpOle 
Version           : 2.0
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: April 3, 1999