Open and close a pdf document

I must open a pdf document so I ask you if this code is ok......

Private Sub Comando201_Click()
 Dim AcroApp As Acrobat.CAcroApp
        Dim PDDoc As Acrobat.CAcroPDDoc
        Set AcroApp = CreateObject("AcroExch.App")
        Set PDDoc = CreateObject("AcroExch.PDDoc")
       
        AcroApp.Show
        PDDoc.Open ("l:\toledo.pdf")
        PDDoc.OpenAVDoc ("l:\toledo.pdf")
       

End Sub


.....And I have a button that close the pdf open with the code upon

Private Sub close_Click()
Dim avdoc As Acrobat.CAcroAVDoc
Dim AcroApp As Acrobat.CAcroApp
        Dim PDDoc As Acrobat.CAcroPDDoc
        Set AcroApp = CreateObject("AcroExch.App")
        Set avdoc = CreateObject("AcroExch.avdoc")
        Set PDDoc = CreateObject("AcroExch.PDDoc")
        AcroApp.CloseAllDocs
        Set avdoc = Nothing
        Set AcroApp = Nothing
End Sub

In this case the document is closed but Acrobat is already active so if I try to re-open the pdf I receive the error that the file is already open.....how can I close the pdf totally?????
dmpuserAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Arthur_WoodCommented:
you are creating the AcroApp and PDDoc objects locally in the two subs, and they are different.

You need to make thse tow objects at the Module Level:


Dim AcroApp As Acrobat.CAcroApp
Dim PDDoc As Acrobat.CAcroPDDoc
Private Sub Comando201_Click()
 
        Set AcroApp = CreateObject("AcroExch.App")
        Set PDDoc = CreateObject("AcroExch.PDDoc")
       
        AcroApp.Show
        PDDoc.Open ("l:\toledo.pdf")
        PDDoc.OpenAVDoc ("l:\toledo.pdf")
       

End Sub


Private Sub close_Click()

        AcroApp.CloseAllDocs
        Set PDDoc = Nothing
        Set AcroApp = Nothing
End Sub


See if that works for you.

But , also, how is this a DATABASE question?  I think you have posted this question in the wrong TA.  This is Databases, not programming, or Visual Basic - either of which would be a more appropriate TA for this question.

AW

dmpuserAuthor Commented:
I have apported modify you have post ......so I have 2 problems

Why I have 2 files pdf opend? I have deleted one of these two lines but No file are opened ...

PDDoc.Open ("l:\toledo.pdf")
        PDDoc.OpenAVDoc ("l:\toledo.pdf")

...and after close the file pdf How can I close the Acrobat application ?
Arthur_WoodCommented:
I was simply offering advice based on the fact that you were creating the objects local to the Sub where they were dimmed, and that was clearly not what you wanted to be doing.  I have no idea whatsoever what an AVDoc is, in Actobat terms, so I have no idea why you were opeing the toledo.pdf twice.  I suumed that you had some idea of what you were doing.  I would expect that there would be a method on the AcroApp object that would close the application as well.  Again, no idea, as I do not use Acrobat myself.

AW
Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.

dmpuserAuthor Commented:
hOW CAN I OPEN MY PDF FILE? IN FACT IF I USE ONLY ONE OF TWO LINES I CANNOT OPEN THE FILE!
Arthur_WoodCommented:
no need to shout!!!  As I indicated earlier, why is this question posted in the DATABASE thread?  I would expect that you would be much more likely to find someone who has worked with Acrobat in a simialr manner, if you requested that this question line be MOVED to a more appropriate TA (such as Programming, or Visual Basic or Adobe Acrobat (surprise - look in Applications>Graphics>Adobe Acrobat).  

If you use both lines, does your document open?  

Perhaps you then need to assign the 'open' document to the Acrobat instance that you have opened - Is there an ActiveDoc (just a guess) method on the AcroApp object (something like Set AcroApp.ActiveDoc = PDDoc - like I said, just a guess).

AW
dmpuserAuthor Commented:
yes the document is opened if I use both the lines
Arthur_WoodCommented:
then what is the problem?  So it requires two lines of code...big deal.

AW

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dmpuserAuthor Commented:
when I close my pdf with the code upon then adobe acrobat window remain open and minimized too
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.