ACC95: Using MS Word's FileClose/DocClose Statements in OLE (156226)
The information in this article applies to:
- Microsoft Access for Windows 95 7.0
This article was previously published under Q156226 SYMPTOMS
Advanced: Requires expert coding, interoperability, and multiuser skills.
The WordBasic FileClose and DocClose statements unexpectedly close
Microsoft Word when used through OLE automation.
This article assumes that you are familiar with Visual Basic for
Applications, Word Basic and with creating Microsoft Access applications
using the programming tools provided with Microsoft Access. For more
information about Visual Basic for Applications, please refer to the
"Building Applications with Microsoft Access for Windows 95" manual.
CAUSE
The FileClose and DocClose statements close Microsoft Word unexpectedly if
the following conditions are true:
- Microsoft Word is started through OLE automation. In other words,
Microsoft Word is not previously running when the OLE Automation
session begins.
- The FileClose or DocClose statement is used via OLE Automation from
any OLE Automation client.
- Microsoft Word is not visible during the operation.
RESOLUTION
Use either of the following two methods to work around this behavior.
Method 1: Make Microsoft Word Visible Before the FileClose Statement
This method uses the AppShow statement to make Microsoft Word visible
before using the FileClose/DocClose statement. The AppShow statement is a
Microsoft WordBasic statement that can be issued through OLE automation to
make Microsoft Word visible.
- Open the sample database Northwind.mdb.
- Create a module and type the following procedure:
Sub WordTest()
Dim objWordBasic As Object
Set objWordBasic = CreateObject("Word.Basic")
objWordBasic.AppShow
objWordBasic.FileNewDefault
objWordBasic.INSERT "This is test 1"
objWordBasic.FileSaveAs "C:\Testword.doc", 0
objWordBasic.FileClose 1
objWordBasic.FileNewDefault
objWordBasic.INSERT "This is test 2"
objWordBasic.FileSaveAs "C:\Testword.doc", 0
objWordBasic.FileClose 1
End Sub
- To test this procedure, type the following line in the Debug window,
and then press ENTER.
Note that Microsoft Word correctly saves the document to your C:\
folder.
Method 2: Create the Word Object Based on the Word.Document Class
This method uses two OLE automation objects. The first object is created
using the Word.Document class. The second object is created off the
Application.WordBasic class that is derived from the first object.
- Open the sample database Northwind.mdb.
- Create a module and type the following procedure:
Sub WordTest()
Dim objWordDoc As Object
Dim objWordBasic As Object
Set objWordDoc = CreateObject("Word.Document")
Set objWordBasic = objWordDoc.Application.WordBasic
objWordBasic.FileNewDefault
objWordBasic.INSERT "This is test 1"
objWordBasic.FileSaveAs "C:\Testword.doc", 0
objWordBasic.FileClose 1
objWordBasic.FileNewDefault
objWordBasic.INSERT "This is test 2"
objWordBasic.FileSaveAs "C:\Testword.doc", 0
objWordBasic.FileClose 1
End Sub
- To test this procedure, type the following line in the Debug window,
and then press ENTER.
Note that Microsoft Word correctly saves the document to your C:\
folder.
REFERENCES
For more information about the FileClose and DocClose statements, search
for FileClose statement and DocClose statement using the Microsoft Word
for Windows 95 Help Index.
For more information about creating objects with OLE Automation, search on
the phrase Create an object with OLE Automation, and then
CreateObject Function or Using Microsoft Access as an OLE Automation
Controller using the Microsoft Access for Windows 95 Answer Wizard.
Microsoft Access, "Building Applications with Microsoft Access for Windows
95," version 7.0, Chapter 11, "Communicating with Other Applications,"
pages 262-290.
Modification Type: | Minor | Last Reviewed: | 10/11/2006 |
---|
Keywords: | kbinterop kbprb kbProgramming KB156226 |
---|
|