2
votes

I have a few functions that generate Word, Excel or PDF documents. For example, the one I'm working on is exporting a report to a PDF file. After closing the report, it opens another PDF form created with LiveCycle ES 8.2 and it fills it with data from a database. After this, the document is closed, but for some reason, the instance of Acrobat is still open in foreground with no document opened.

Here is the code:

DoCmd.OpenReport "myReport", acViewPreview
DoCmd.OutputTo acOutputReport, "", acFormatPDF, "C:\myReport.pdf", False
DoCmd.Close acReport, "myReport"

Dim gApp, avDoc, pdDoc, jso

Set gApp = CreateObject("AcroExch.app")
Set avDoc = CreateObject("AcroExch.AVDoc")
If avDoc.Open(exprPDF, "") Then
    Set pdDoc = avDoc.GetPDDoc()
    Set jso = pdDoc.GetJSObject

    '[...]

    pdDoc.Save PDSaveIncremental, FileNm 'Save changes to the PDF document
    pdDoc.Close 'Close the PDF document
End If

avDoc.Close (True)
Set gApp = Nothing
Set avDoc = Nothing

myReport never opens any instance of Acrobat. The line avDoc.Open does. I would like Acrobat to be closed when I do avDoc.close. Any ideas?

3
I notice 2 things that I would try... gApp.Close and setting gApp to nothing after avDoc, so you're not trying to confuse things by having items opened/closed out of order - SeanC
Sounds to me like you have unreasonable expectations. Normally closing a document shouldn't close the application that is displaying the document. Is there a gApp.Quit method or something simalar? - Daniel
@SeanCheshire Already tried setting everything to nothing but it doesn't change much. As for gApp.Close and gApp.Quit, both methods exist and do nothing. My script fills the PDF form and then save it. It must be totally transparent to the user. - dan

3 Answers

2
votes

I think you should add:

gApp.Exit

before the

Set gApp = Nothing

That seems to do the tick, but the app is still there, hidden... To Actually kill Acrobat try this method here with "Acrobat.exe": How can I kill task manager processes through VBA code? That method is a bit of a sledge hammer, but it works.

0
votes

After some more tests, I need to both close and quit all document objects to ensure that the app quits if there is no remaining opened document.

0
votes

I have just experienced the same issue and found the following solution:

AVDoc.Close (True)
**AcroApp.Hide**

Set AcroApp = Nothing
Set AVDoc = Nothing