ACC2: How to Programmatically Embed or Link an Object in a FormLast reviewed: May 14, 1997Article ID: Q114214 |
The information in this article applies to:
SUMMARYModerate: 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 INFORMATIONYou 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 ObjectTo link an object in an object frame on a form, first set the following properties:
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 ObjectTo embed an object in an object frame on a form, first set the following properties:
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 ObjectTo create an empty embedded object in an object frame, first set the following properties:
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 REFERENCESMicrosoft 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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |