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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automation Error Handling

Status
Not open for further replies.

cascot

Programmer
Jan 30, 2002
127
CA
I have code similar to that below to initiate an instance of Microsoft Word from within Access. How do I ensure that if an error occurs, the instance of Word gets shut down?
In the early stages of the coding when errors occurred I had to go into the Windows Task manager and manually close down the WINWORD.EXE process. Can anyone tell me which code I should include in my error handling?

Dim appWord As Object
Dim docWord As Word.Document
Dim strTemplateDoc As String
Dim CorePath As String

CorePath = GetRootPath

Set appWord = New Word.Application

strTemplateDoc = CorePath "\Template.doc"

Set docWord = appWord.Documents.Add(strTemplateDoc)

[Code to do the processing I'm doing]

appWord.Visible = False

 
There are a few ways to do this. The most widely used is something like:

Code:
sub whatEver
 on error goto ERROR_HANDLER
 '... code that might generate an error ...
 exit sub
ERROR_HANDLER:
 '... code that handles the error ...
end sub

Look at the options in MS-Access. By default, error handling is set to "break in class modules". I honestly can't think of any reason why this is a handy setting. Better set it to "break on unhandled errors". For debugging, it can be wise to set it to "break always" temporarily.

Best regards
 
DonQuichote,

Thanks for your reply.

I maybe didn't explain things too well. I know all about error handling and already have it in place within my code (as it always should be). My question was what code to place in the error handling routine in order to close the instance of Microsoft Word that would be left hanging around in memory if an error occurred.

As it happens I now know the code and have implemented it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top