Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook98 - Program Error

Status
Not open for further replies.

SHardy

Programmer
May 9, 2001
231
GB
I have an Outlook98 application that uses Word97 to print the records in my folder. It does this by:

1) Starting the Word app.
2) Creating a document based on a template.
3) Passing values from Outlook.
4) Printing the document.
5) Discarding the document.
6) Quitting Word.

The first print is fine. However, from then on it all prints OK but I get the following error message:

*******************************************************
Program Error

WINWORD.exe has generated errors and will be closed by Windows.
You will need to restart the program.

An error log is being generated.
*******************************************************

It seems that I can't be closing down either the Word app or the document properly.

Currently using the following:

Const wdDoNotSaveChanges = 0
oWordDoc.Close wdDoNotSaveChanges
oWordApp.Quit

Set oWordDoc = Nothing
Set oWordApp = Nothing

Any ideas why I am getting this message and how I can stop it?

Thanks.
 
I just discovered something, entirely by accident.

If I open a Word document from an Exchange folder, and then close Word without first closing the document, I get the same error message. If I close the document first and then close the application then no error.

Also, if the last Word document I had opened was from the file system, then I open a doc from the Exchange folders, the error does not appear if I then close Word without first closing the document. But upon opening another Exchange folder document and closing in the same way - there's the error again.

This explains two things:

1) Why sometimes the first print from my Outlook app doesn't produce the error.

2) That the error must be caused by the document not being closed properly.

Still confused though, 'cause I have a line in there telling Word to close the document without saving.

As a safe guard is there a command to say close ALL Word documents without saving?

Oh, while I was writing this I have thought of something else that may confuse matters:

I have the template saved to the Exchange folder, but don't actually use it from there (didn't know how to point Word to it). So what I do is save it from the Exchange folder to the local drive, then create a new document based on the template on the local drive.

So is the problem stemming from when I save from the public folder? Or, as I create the new document from code in an Exchange folder, is the new document created there? Thus causing the problem described above.

Example code:

:
:
Set MyNameSpace = Application.GetNameSpace("MAPI")
Set MainPublicFolder = MyNameSpace.Folders("Public Folders")
Set AllPublicFolders = MainPublicFolder.Folders("All Public Folders")
Set PublicCCFolder = AllPublicFolders.Folders("JMC - IT Change Control")
Set PrintTemplate = PublicCCFolder.Items("Change Control Record.dot")

PrintTemplate.Attachments.Item(1).SaveAsFile "C:\Change Control Record.dot"
Set oWordDoc = oWordApp.Documents.Add("C:\Change Control Record.dot")
oWordDoc.Unprotect
:
:
Const wdDoNotSaveChanges = 0
oWordDoc.Close wdDoNotSaveChanges
oWordApp.Application.Quit

Set oWordDoc = Nothing
Set oWordApp = Nothing
:
:
 
Well I installed the update for Word (wd97mcrs.exe) and for a moment thought it had worked. My initial test was just to open a Word document from a public folder, and then to close the application without first closing the document. It did this several times over without producing the error.

However, when I ran the print function from my Outlook app I was still getting the error.

This confused me again, as why did I not get the error on my first test. I went back to this method of opening the document and closing the Word application and found out the following (which I had obviously missed previously - sorry):

When I open a document from an Exchange folder I get the error if I don't wait for everything to fully load before quitting Word. I.e. the hourglass is still showing.
If I open the document, wait for the hourglass to go and THEN quit Word I don't get the error.

Therefore do I need my code to WAIT between each action to allow Word and the document to load completely?
If this is a YES, then how do I do this?
 
I have 60 users working on a LAN. A frequent problem is that users are unable to open attachments. Attachment size doesn't seem to matter. One user can open the attachment but another cannot. I've checked to see if there are any filters on or rules operating but in each case there is none. Can you advise ? One extremely grateful Journeyman Administrator.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top