ACC2: How to Open/Edit MS Word Document in Bound Object Frame (132240)



The information in this article applies to:

  • Microsoft Access 2.0

This article was previously published under Q132240

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.
  1. 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.
  2. Start Microsoft Access and open the Employees form in Design view.
  3. 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.
  4. 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
    						
  5. 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.
  6. 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:

123859 ACC: Sample OLE Automation for Microsoft Word and Microsoft Excel

124862 ACC: Sending the Current Record to Word with OLE Automation

Modification Type:MajorLast Reviewed:11/6/2000
Keywords:kbhowto kbinterop KB132240