ACC2: How to Open/Edit MS Word Document in Bound Object Frame
ID: Q132240
|
The information in this article applies to:
SUMMARY
This article demonstrates sample Access Basic code that you can set for the
OnDblClick property event procedure of a bound OLE object control so that
you can open/edit a previously embedded OLE object. If no object exists, a
new Microsoft Word document is embedded.
This article assumes that you are familiar with Access Basic and with
creating Microsoft Access applications using the programming tools provided
with Microsoft Access. For more information about Access Basic, please
refer to the "Building Applications" manual.
MORE INFORMATION
To create the sample Access Basic code so that you can open/edit a
previously embedded OLE object, follow these steps.
CAUTION: Following the steps in this example will modify the sample
database NWIND.MDB. You may want to back up the NWIND.MDB file, or perform
these steps on a copy of the NWIND database.
- Create a document in Microsoft Word to be used as the template for the
new embedded documents, and save it as C:\TEST.DOC.
NOTE: If you change the name or location of this document, be sure to
change the sample code to reflect this change.
- Start Microsoft Access and open the Employees form in Design view.
- View the property sheet of the OLE object control bound to the Photo
field and make sure that the AutoActivate property is set to Manual.
- On the View menu, click Code and type the following code in the Module
window:
Sub Photo_DblClick (Cancel as Integer)
On Error GoTo NoOLEObject
Me![Photo].Verb = VERB_OPEN
Me![Photo].Action = OLE_ACTIVATE
Exit Sub
NoOLEObject:
If Err = 2684 Then
Me![Photo].OLETypeAllowed = OLE_EMBEDDED
Me![Photo].SourceDoc = "C:\TEST.DOC"
Me![Photo].Action = OLE_CREATE_EMBED
Resume
Else
MsgBox "Error - " & Str(Err) & " : " & Error
End If
Exit Sub
End Sub
- Use one of the following methods to create a new module:
- Create a new module named DATA CONSTANTS and type the following
lines in the Declarations section:
Global Const VERB_OPEN = -2
Global Const OLE_ACTIVATE = 7
Global Const OLE_EMBEDDED = 1
Global Const OLE_CREATE_EMBED = 0
-Or-
- Create a new module named DATA CONSTANTS, and on the File menu,
click LOAD TEXT. Click the CONSTANT.TXT file in the ACCESS directory
and click the Merge button. Close and save the module.
- View the Employees form in Form view. Note that double-clicking the
object frame activates the OLE object. If an OLE object does not exist,
double-clicking the object frame embeds a new Word document into
the object frame.
NOTE: Some embedded objects may look slightly garbled if the OLE object
frame's SizeMode property is set to Zoom or Stretch as is the case with the
Employees form in the sample database NWIND.MDB.
REFERENCES
Microsoft Access "Building Applications," version 2.0, Chapter 13,
"Creating an Embedded OLE Automation Object from a File," page 297
For more information about OLE Automation and the Verb property, search for
"Verb" using the Microsoft Access Help index.
For more information about OLE Automation, please see the following
articles in the Microsoft Knowledge Base:
Q123859 ACC: Sample OLE Automation for Microsoft Word and Microsoft
Excel
Q124862 ACC: Sending the Current Record to Word with OLE Automation
Additional query words:
automate
Keywords : kbinterop IntpOlea
Version : 2.0
Platform : WINDOWS
Issue type : kbhowto