I am creating a mail merge, and wish to release the object once I am done with it.
Simply put, is it bad practice to use TRY-CATCH inside the finally block? As well, my code is complaining because I am releasing oDoc with the possibility of never assinging it. What would be the best way to handle said issue?
Code:
Dim oWord As New Word.Application
Dim oDoc As Word.Document
Try
oDoc = oWord.Documents.Open("C:\Desktop\doc.docx", , True)
oWord.Visible = True
oDoc.MailMerge.OpenDataSource("C:\mytestDB.accdb", , , True, True, , , , , , , Connection:="RENEWAL", SQLStatement:="SELECT * FROM [RENEWAL]")
oDoc.MailMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument
oDoc.MailMerge.Execute()
oDoc.Application.Quit(Word.WdSaveOptions.wdDoNotSaveChanges)
Catch Ex As Exception
MsgBox("An Error Occured! " & Ex.Message)
Finally
Try
Marshal.ReleaseComObject(oDoc) 'release backwards to creation
Marshal.ReleaseComObject(oWord)
Catch ex As Exception
MsgBox("Could not release object!")
End Try
End Try