objWord.Application.Quit crashes Word97 
Author Message
 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



Tue, 21 Nov 2000 03:00:00 GMT  
 objWord.Application.Quit crashes Word97

Hmm. I don't have a fax transport on my machine, so I can't test this. But
perhaps this has something to do with the fact that SendFax launches a
wizard, which is a form of add-in. Have you tried sending the document as an

You could do this using CDO.

Off topic, but if you want a faster way to set bookmark text, try this:

    ActiveDocument.Bookmarks("GuestName").Range.Text = strGuestName

Saves moving the selection (cursor) through the document.

--
Remove ZZZ from email address.

Quote:

>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



Tue, 21 Nov 2000 03:00:00 GMT  
 objWord.Application.Quit crashes Word97

Hi Adam,
skip the "objWord.Application.Quit" in your code. When the Automation object
is Set = Nothing your Word object is dead.



Tue, 21 Nov 2000 03:00:00 GMT  
 objWord.Application.Quit crashes Word97

Adam,

Quote:
> ' 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

It would appear that there is a timing problem, and that if you
automatically proceed through the faxing operation something is set or
cleaned up properly.  If you want to avoid the really messy business of
debugging internal Word operations, just include the PrintPreview in the
normal processing and get on with your life.


 Sending from beautiful, midtown Mukilteo
 4.02 build 244 (32-bit)for WG, Win95, Fri, 05 Jun 1998 08:07 PDT



Tue, 21 Nov 2000 03:00:00 GMT  
 objWord.Application.Quit crashes Word97

Adam,

well, I dont know, if it is the same as if you would use a printer, but you can
try the following:
    WHILE objWord.BackgroundPrintingStatus > 0
    WEND
these lines wait for the PrintOut to finish.

I do not know if it works for fax too, but maybe it helps.

regards
GUENTER

Quote:

> 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

  vcard.vcf
< 1K Download


Wed, 22 Nov 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Visio Crashes on Quit command

2. Quit method causes crash called from automation

3. Help on Crashing Application (DLL Crash)

4. hta app crashes on quit ?

5. Resetting original system colors on quitting application

6. Disable Application Quit ("X") Button

7. Auto Quit Application after No Activity

8. Newbie Application.Quit Question

9. Acc97: Application.Quit hangs task

10. Application.Quit statement resets Variables?

11. Access 97 - Application.Quit does not work if msgbox is displayed

12. Repost -- ACC97: GPF on Application.Quit

 

 
Powered by phpBB® Forum Software