
objWord.Application.Quit crashes Word97
Hi All,
I'm using automation in Access 97 to a fax a document from Word 97 using
Microsoft Fax - see attached code. When fDebug is True everything works
fine. When fDebug is False, the command objWord.Application.Quit causes:
WINWORD caused an invalid page fault in
module KERNEL32.DLL at 0137:bff9a5d4.
Anyone any ideas what's going on?
Cheers,
- Adam.
Public Function SendFax(strDocumentFileName As String,
strDestinationFaxNumber As String, strGuestName As String, strRoomNumber As
String, strHotelName As String, strTitle As String, strSubject As String) As
String
On Error GoTo ErrorHandler
' Set fDebug to True to print-preview the faxes rather than sending
them.
Dim fDebug As Boolean
fDebug = True
Dim objWord As Word.Application
Set objWord = CreateObject("Word.Application")
With objWord
.Visible = True
.Documents.Open (gstrDocumentPath & strDocumentFileName)
' Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("GuestName").Select
.Selection.text = strGuestName
.ActiveDocument.Bookmarks("HotelName").Select
.Selection.text = strHotelName
.ActiveDocument.Bookmarks("RoomNumber").Select
.Selection.text = strRoomNumber
.ActiveDocument.Bookmarks("Title").Select
.Selection.text = strTitle
End With
' Send the fax
If fDebug Then
objWord.ActiveDocument.PrintPreview
Call MsgBox("Click OK to continue")
Else
objWord.ActiveDocument.SendFax address:=strDestinationFaxNumber,
Subject:=strSubject
End If
' Close the document without saving changes.
objWord.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
' Quit Microsoft Word 97 and release the object variable.
objWord.Application.Quit ' *** Winword crashes here
Set objWord = Nothing
SendFax = "ok"
Exit Function
ErrorHandler:
SendFax = Error(Err.Number)
objWord.Application.Quit
Set objWord = Nothing
End Function